有一个表结构如下:
A B
-------------
张三 1
张三 5
李四 2
王五 3
王五 5
王五 7
现要求将A列中有重复值的记录筛选并统计出来,结果如下:
A B
-------------
张三 2
王五 3
请高手支招,最好能用一条语句搞定,不要用存储过程,临时表,游标等。
------解决方案--------------------------------------------------------
参照:
select a.aInt,a.aText
from table a,(select 主键=min(主键) from table group by aInt)b
where a.主键=b.主键
------解决方案--------------------------------------------------------
select A, count(A) as 'B '
from yourtable
group by A
------解决方案--------------------------------------------------------
select max(a) as a,count(B) as b from 表 group by a
------解决方案--------------------------------------------------------
用select A, count(A) as 'B '
from yourtable
group by A
的在加个条件呗?
select * from
(
select A, count(A) as 'B '
from yourtable
group by A
) amandag
where amandag.B> 1