SELECT count(`tieba_info`.*) as `total`,`tieba_cat`.`id` as `id` , `tieba_cat`.`name` as `name` ,`tieba_cat`.`desc`
FROM `tieba_cat` 
left join `tieba_info` on `tieba_cat`.`id`=`tieba_info`.`cat_id`
ORDER BY `tieba_info`.`total` DESC 
LIMIT 0 , 2000 这个语句怎么是错误的啊?
如何解决?

解决方案 »

  1.   

    mysql 返回:
    #1064 - You 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 `total`,`tieba_cat`.`id` as `id` , `tieba_cat`.`name` as `name` ,`tieba_ca' at line 1 
      

  2.   

    1 你可以用 count(`tieba_info`.id) 或其它的字段,不要用 `tieba_info`.*2 统计函数不要把查询也放里面,返回不一样 样..
      

  3.   

    感觉问题处在count那里,要不你把count去掉运行看看。遇到这种问题是要逐一排查。
      

  4.   

    还有:ORDER BY `tieba_info`.`total` DESC ---〉ORDER BY `total` DESC  在试试
      

  5.   

    把表結構和數據都貼點出來吧。。還有你mysql的版本。
      

  6.   

    SELECT count(`tieba_info`.*) as `total`,`tieba_cat`.`id` as `id` , `tieba_cat`.`name` as `name` ,`tieba_cat`.`desc`
            FROM `tieba_cat` 
            left join `tieba_info` on `tieba_cat`.`id`=`tieba_info`.`cat_id`
            ORDER BY `count(`tieba_info`.*) DESC 
            LIMIT 0 , 2000 
      

  7.   


    后来好了,是因为需要GROUP BY这个语句,才可以的。