n********6 发帖数: 1511 | 1 table:
transactionid, product
1 apple
2 orange
3 apple
4 pear
5 watermellon
6 orange
7 orange
output:
product, counter
apple 2
orange 3
谢谢。 | B*****g 发帖数: 34098 | 2 you should be better than that!
http://www.w3schools.com/SQL/sql_having.asp
【在 n********6 的大作中提到】 : table: : transactionid, product : 1 apple : 2 orange : 3 apple : 4 pear : 5 watermellon : 6 orange : 7 orange : output:
| g***l 发帖数: 18555 | 3 GROUP BY having cout(*) >1不就行了,基础不扎实 | n********6 发帖数: 1511 | | e*********y 发帖数: 29 | 5 没事做,给你完整的答案.呵呵! SQL Server 2005
create database neii
create table production
(
transactionid int primary key,
product char(25)
)
insert into production (transactionid, product) values ('1', 'apple')
insert into production (transactionid, product) values ('2', 'orange')
insert into production (transactionid, product) values ('3', 'apple')
insert into production (transactionid, product) values ('4', 'pear')
insert into production (transactionid, product) values ('5', 'watemellon')
insert into production (transactionid, product) values ('6', 'orange')
insert into production (transactionid, product) values ('7', 'orange')
select product,count(product) as counter from production group by product
having count(*)>1 |
|