怎么样使用count来比较大小(50分)

  • 主题发起人 主题发起人 DancingAgain
  • 开始时间 开始时间
D

DancingAgain

Unregistered / Unconfirmed
GUEST, unregistred user!
大家好!
数据集如下:

我希望找出至少有2个pc.id的maker列元素
I have tried this statement, but it is error!
Select maker from table1
where count(pc.id) > 2
group maker;

maker pc.id
a 1
a 2
a 3
b 4
b 5

谢谢
 
大家好!
数据集如下:

我希望找出至少有2个pc.id的maker列元素
I have tried this statement, but it is error!
Select maker from table1
where count(pc.id) > 2
group by maker;

maker pc.id
a 1
a 2
a 3
b 4
b 5

谢谢

 
select maker from table1 group by maker having count(pc.id)>2
 
dear dq:
Thank you!
I have the similar question to get helps from you!

given two relations
1. product(maker, model, type)
maker model type
a 1001 pc
a 1002 pc
a 1003 pc
b 1004 printer
b 1005 pc
c 1006 pc
.
.
2.pc(model, speed)
model speed
1001 133
1002 166
1003 166
1004 123
....

Suppose model is unique for each row, use sql to represent
find the makers of pc'c with at least three different speeds?

I don't know how to count the record line:
i give the statement(this is error!!)

select maker from product,pc
where product.model = pc.model
and product.type='pc'
group by maker
having count(distinct speed) >=3;

Thank you


 
Try this:

select maker from product
left join pc on product.model=pc.model
where product.type='pc'
group by maker having count(distinct speed)>=3

or:

select maker from
(select a.maker,b.speed from product a
left join pc b on a.model=b.model
where a.type='pc') a
group by maker having count(distinct speed)>=3
 
后退
顶部