+ -
当前位置:首页 → 问答吧 → mysql count函数的使用问题

mysql count函数的使用问题

时间:2011-09-19

来源:互联网

今天遇到个问题需要根据一个表的userid到另一个表中统计这个userid出现的行数像下面这样
select userid,loginname,(select count(*) from table1 where table1.userid = userid)) as num where userid > 2000
运行这个语句得出的num是不对的,主要是userid > 2000的原因,改成select userid,loginname,(select count(*) from table1 where table1.userid = 2000)) as num where userid = 2000
这样没问题但是满足不了查询的需要,请问要怎么改?

作者: wxq1987525   发布时间: 2011-09-19

select userid,loginname,(select count(*) from table1 where table1.userid = userid)) as num where userid > 2000


这里面怎么没有from

作者: rucypli   发布时间: 2011-09-19

贴建表及插入记录的SQL,及要求结果出来看看

作者: WWWWA   发布时间: 2011-09-19

相关阅读 更多

热门下载

更多