我有一个这样的数据库:
身份证 | 访问代码
并且代码在行中重复。我想要一个看起来像这样的选择
访问代码 | 表中有多少条目与此 AcessCode 匹配
像这样:
select AccessCode, COUNT(ID) as Entires
from YourTable
group by AccessCode
如果你想处理空值(id)......
select
accesscode,count(*) as total
from
t
group by accesscode
order by total;
见 sqlfiddle:http ://sqlfiddle.com/#!6/79fe2/1
select AccessCode, count(AccessCode) from sometable group by AccessCode