表A:
BOOK是字段
A
B
C
D
E
B
C
要输出的结果是:
BOOK SUMCOUNT
B 2
C 2
select distinct BOOK ,count(BOOK) as 'SUMCOUNT' form A group by
BOOK having count(book)>1
SELECT DISTINCT BOOKID ,COUNT(BOOKID) AS 'SUMCOUNT'
FROM DBO.BOOK GROUP BY
BOOKID HAVING BOOKID IN('B','C')
这是最最基本的Group by,属于面试必考.
看一下分组的SQL语句就可以了。
select distinct Book ,count(Book) from A
group by Book
having count(Book) > 1