读书人

mysql不支持这条sql,应该如何写

发布时间: 2012-02-21 16:26:23 作者: rapoo

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

读书人网 >Mysql

热点推荐