sql语句将两个查询结果并列输出
三个表:scan_shops:id(店铺id)、shopname(店铺名称)school_id(学校id)scan_school:school(学校名称)school_i...
三个表:
scan_shops: id(店铺id)、shopname(店铺名称)school_id(学校id)
scan_school: school(学校名称) school_id(学校id)
scan_goods_shop: nums(产品数量) goods_price(商品价格) ,shopid(店铺id)
要查学校id,学校名称,店铺名称,以及每个店铺各自所有产品价格乘数量的总和
where条件为goods_status(是否存在该商品)=1
要像这样的结果,不用合并单元格,要sql语句
已经写出子查询如下:
select sum(nums*goods_price) as money from scan_goods_shop where goods_status=1 group by shopid
主查询如下:
select sh.school_id,sh.school,s.shopname FROM (scan_school as sh INNER JOIN scan_shops as s on sh.school_id=s.school_id)INNER JOIN scan_goods_shop as gs on gs.shopid=s.id where gs.goods_status=1 GROUP BY s.shopname ORDER BY s.school_id
或者把这两句的结果二维数组合并成一个二维数组也行 展开
scan_shops: id(店铺id)、shopname(店铺名称)school_id(学校id)
scan_school: school(学校名称) school_id(学校id)
scan_goods_shop: nums(产品数量) goods_price(商品价格) ,shopid(店铺id)
要查学校id,学校名称,店铺名称,以及每个店铺各自所有产品价格乘数量的总和
where条件为goods_status(是否存在该商品)=1
要像这样的结果,不用合并单元格,要sql语句
已经写出子查询如下:
select sum(nums*goods_price) as money from scan_goods_shop where goods_status=1 group by shopid
主查询如下:
select sh.school_id,sh.school,s.shopname FROM (scan_school as sh INNER JOIN scan_shops as s on sh.school_id=s.school_id)INNER JOIN scan_goods_shop as gs on gs.shopid=s.id where gs.goods_status=1 GROUP BY s.shopname ORDER BY s.school_id
或者把这两句的结果二维数组合并成一个二维数组也行 展开
1个回答
2017-09-21
展开全部
如果是2个SQL语句的话。如果列名都一样,使用UNIONALL就可以了。例如select*from表1UNIONALLselect*from表2就可以了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询