column " " must appear in the GROUP BY clause or be used in an aggregate function

用了聚集函数 前面要select的列必须出现在聚集函数或者groupby里,不然它不知道怎么分配
查询大于平均WEIGHT的零件,列出他们的供应商代码(SNO),零件代码(PNO),工程代码(JNO),供应数量(QTY)

insert into P(Pno,Pname,color,weight)
values
('P1','螺母','红',12),
('P2','螺栓','绿',17),
('P3','螺丝刀','蓝',14),
('P4','螺丝刀','红',14),
('P5','凸轮','蓝',40),
('P6','齿轮','红',30);

insert into SPJ(Sno,Pno,Jno,QTY)
values
('S1','P1','J1',200),
('S1','P1','J3',100),
('S1','P1','J4',700),
('S1','P2','J2',100),
('S2','P3','J1',400),
('S2','P3','J2',200),
('S2','P3','J4',500),
('S2','P3','J5',400),
('S2','P5','J1',400),
('S2','P5','J2',100),
('S3','P1','J1',200),
('S3','P3','J1',200),
('S4','P5','J1',100),
('S4','P6','J3',300),
('S4','P6','J4',200),
('S5','P2','J4',100),
('S5','P3','J1',200),
('S5','P6','J2',200),
('S5','P6','J4',500);

1)查询大于平均WEIGHT的零件,列出他们的供应商代码(SNO),零件代码(PNO),工程代码(JNO),供应数量(QTY)

select sno,spj.pno,jno,qty from spj,p where spj.pno=p.pno and weight>(select avg(weight) from p)
select sno,pno,jno,qty from spj where pno in(select pno from p  where weight>(select avg(weight) from p))

错误

select sno,spj.pno,jno,qty from spj,p where spj.pno=p.pno  having weight>(select avg(weight) from p) 

错 having要和group by 一起用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值