mysql不支持这条sql,应该怎么写
另一个帖问过:http://community.csdn.net/Expert/topic/5750/5750338.xml?temp=.2292597
t1(標題表)
id
t2(回復表1,會有多條回復,關係:t2.t1id=t1.id)
t1id
============
列出t1的數據,以回復數多少排序,怎麼寫?
=========================================
select a.*,b.cnt as 回复数
from t1 as a
left join (select t1id,count(*) as cnt from t2 group by t1id) as b on a.id=b.t1id
order by b.cnt desc
================
在我的机上可以,在服务器上就不可以了,可能是mysql版本底,不改变版本情况下怎么实现呢?
出错:
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 'select t1id,count(*)
------解决方案--------------------你的机器上的MYSQL版本是多少?
你的服务器上的MYSQL版本是多少?
------解决方案--------------------你的sql语句里有子查询,4.1版本以下的mysql不支持,请使用4.1版本以上的mysql
另外,你那个帖子是在mssql版发的,又没有明确说明,人家当然就给你mssql版本的sql了
------解决方案--------------------那就改成简单的连接:
select a.*,b.cnt as 回复数
from t1 as a ,(select t1id,count(*) as cnt from t2 group by t1id) as b where a.id=b.t1id order by b.cnt desc
------解决方案--------------------select a.*,b.cnt as 回复数
from t1 as a ,(select t1id,count(*) as cnt from t2 group by t1id) as b where a.id=b.t1id order by b.cnt desc