mysql查询求助:一个非常困难的问题
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/25 09:46:28
mysql查询求助:一个非常困难的问题
有2个表:
表A:字段 type qty mark(值为yes或no)
表B:字段 type name(值为1或2或3)
要求:从表A中取出符合以下要求的记录(取出的列为B表中的type和sum(qty) )
1.B.name=1得出相应的B.type数据集,为第2步计算做准备;
2.B.type=A.type;
3.A.mark=no; --选出A表中mark=no的记录
4.group by B.type --分类计算出符合以上条件的A表中type的sum(qty)
这么写
select A.type,sum(A.qty) from A join B on B.type=A.type group by A.type having A.mark=no and B.name=1;
总是输出错误:ERROR 1054 (42S22):Unknown column 'A.mark' in 'having clause'
有2个表:
表A:字段 type qty mark(值为yes或no)
表B:字段 type name(值为1或2或3)
要求:从表A中取出符合以下要求的记录(取出的列为B表中的type和sum(qty) )
1.B.name=1得出相应的B.type数据集,为第2步计算做准备;
2.B.type=A.type;
3.A.mark=no; --选出A表中mark=no的记录
4.group by B.type --分类计算出符合以上条件的A表中type的sum(qty)
这么写
select A.type,sum(A.qty) from A join B on B.type=A.type group by A.type having A.mark=no and B.name=1;
总是输出错误:ERROR 1054 (42S22):Unknown column 'A.mark' in 'having clause'
![mysql查询求助:一个非常困难的问题](/uploads/image/z/5882076-36-6.jpg?t=mysql%E6%9F%A5%E8%AF%A2%E6%B1%82%E5%8A%A9%EF%BC%9A%E4%B8%80%E4%B8%AA%E9%9D%9E%E5%B8%B8%E5%9B%B0%E9%9A%BE%E7%9A%84%E9%97%AE%E9%A2%98)
select A.type,sum(A.qty)
from A join B on B.type=A.type
where A.mark=no and B.name=1
group by A.type ;
from A join B on B.type=A.type
where A.mark=no and B.name=1
group by A.type ;