ljc 发表于 2013-9-11 10:41:10

sql问题怎么解决

A Database Error OccurredError Number: 1140Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clauseSELECT `shops`.*, count(review.catid) as number FROM (`shops`) JOIN `review` ON `shops`.`id`=`review`.`catid`Filename: D:\AppServ\www\goodreview\system\database\DB_driver.phpLine Number: 330
这个问题怎么解决..

Hex 发表于 2013-9-11 14:07:30

贴代码

ljc 发表于 2013-9-11 14:15:42

Hex 发表于 2013-9-11 14:07 static/image/common/back.gif
贴代码

public function shop_goodreview_order_by(){
                $this->db->select('shops.id ,shops.name,count(review.catid) as number');
                $this->db->from('review');
                $this->db->join('shops','review.catid=shops.id');
                $this->db->order_by('number','desc');
                $this->db->group_by(array('shops.id','shops.name'));
                $query=$this->db->get();
                return $query->result();
        }

谢谢哈 解决了 我是加了group_by就好了

ljc 发表于 2013-9-11 14:17:42

Hex 发表于 2013-9-11 14:07 static/image/common/back.gif
贴代码

我还有个问题想问
代码
public function shop_time_order_by(){                $this->db->select('(FROM_UNIXTIME(NOW()-createtime) as diff,name');
                $this->db->order_by('name','asc');
                $query=$this->db->get('shops');
                return $query->result();
        }
错误:
A Database Error OccurredError Number: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as diff, `name` FROM (`shops`) ORDER BY `name` asc' at line 1SELECT (FROM_UNIXTIME(NOW()-createtime) as diff, `name` FROM (`shops`) ORDER BY `name` ascFilename: D:\AppServ\www\goodreview\system\database\DB_driver.phpLine Number: 330

这怎么解决呢

ljc 发表于 2013-9-11 14:19:39

Hex 发表于 2013-9-11 14:07 static/image/common/back.gif
贴代码

额,不好意思 下面的 我少写个括号,这回好使了

Hex 发表于 2013-9-11 17:01:04

太复杂的 SQL 语句建议直接用 query

ljc 发表于 2013-9-11 17:25:46

Hex 发表于 2013-9-11 17:01 static/image/common/back.gif
太复杂的 SQL 语句建议直接用 query

哦,就是写个$sql='';然后$this->db->query($sql);对吧 是这意思吧

Hex 发表于 2013-9-11 18:39:33

ljc 发表于 2013-9-11 17:25 static/image/common/back.gif
哦,就是写个$sql='';然后$this->db->query($sql);对吧 是这意思吧

是的。

ljc 发表于 2013-9-12 09:10:00

Hex 发表于 2013-9-11 18:39 static/image/common/back.gif
是的。

哦哦,谢啦...
页: [1]
查看完整版本: sql问题怎么解决