怎么样查处一列不同id的个数?
ID
1
1
2
2
2
3
3
3
上面的就有1.2.3三种不同的,结果就应该显示3
用select distinct id from table可以得到1.2.3,但是我现在想要显示的是个数,就是显示3
用count可以显示个数,但是count(distinct id)好像不能这样用,请问下有什么办法得到查询结果没有?
ID
1
1
2
2
2
3
3
3
上面的就有1.2.3三种不同的,结果就应该显示3
用select distinct id from table可以得到1.2.3,但是我现在想要显示的是个数,就是显示3
用count可以显示个数,但是count(distinct id)好像不能这样用,请问下有什么办法得到查询结果没有?
SELECT count(*) FROM (SELECT id FROM table_name GROUP BY id HAVING count(*)=1)
意思理解错了
同意1楼,或者是select count(id) from (select id from idtable group by id)