贴一道SQL面试题,希望大家相互讨论
时间:2008-06-17 来源:szlishun
给下面这样的一个表记录:
------------------------------------
from
(
select max(购物人) as name,count(购物人) as cnt
from chanpin
group by 商品名称
) t
where t.cnt >=2
select userName as name,count(userName) as cnt
from exam1
group by userName)t
where t.cnt>=2
------------------------------------
购物人 商品名称 数量
A 甲 2
B 乙 4
C 丙 1
A 丁 2
B 丙 5
给出所有购入商品为两种或两种以上的购物人记录
select t.name
from
(
select max(购物人) as name,count(购物人) as cnt
from chanpin
group by 商品名称
) t
where t.cnt >=2
select t.name,t.cnt from(
select userName as name,count(userName) as cnt
from exam1
group by userName)t
where t.cnt>=2
相关阅读 更多 +