多表联结查询

che0922 2011-06-16 09:30:11

销售表 sell
id selldate num price id_huiyuan id_product remark
主键 出库日期 数量 单价 会员ID 产品ID 备注,字段类型text

会员表 huiyuan
id name
主键 会员名

产品表 product
id brand title
主键 品牌 名称

查询结果:
品牌 商品名称 出库日期 数量 单价 总金额 会员 备注
贝亲 XX奶粉 2011-06-06 4 6 24 张三 尽快发货

我想查询出这样的结果 不清楚怎么拼接查询结果
...全文
79 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xb06620422 2011-06-16
  • 打赏
  • 举报
回复

select brand as 品牌,title as 商品名称,selldate as 出库日期,num as 数量,price as 单价,price*num as 总金额,name as 会员,remark as 备注 from sell
inner join huiyuan a on id_huiyuan=a.id
inner join product b on id_product=b.id
--按这个要求来查是不能分组的,实在要分组 直接聚合分组条件就好了

xb06620422 2011-06-16
  • 打赏
  • 举报
回复

select brand as 品牌,title as 商品名称,selldate as 出库日期,num as 数量,price as 单价,sum(price) as 总金额,name as 会员,remark as 备注 from sell
inner join huiyuan a on id_huiyuan=a.id
inner join product b on id_product=b.id
--按这个要求来查是不能分组的,实在要分组 直接聚合分组条件就好了

che0922 2011-06-16
  • 打赏
  • 举报
回复
忘记说了 要按品牌、日期分类的
tashiwoweiyi 2011-06-16
  • 打赏
  • 举报
回复

select
a.brand as 品牌,
a.title as 商品名称 ,
b.num as 数量,
b.price as 单价,
(b.num * b.price) as 总金额,
c.huiyuan as 会员,
b.remark as 备注
from product a , sell b , huiyuan c where
a.id = b.id_product and c.id = b.id_huiyuan
cd731107 2011-06-16
  • 打赏
  • 举报
回复
select brand as 品牌,title as 商品名称,selldate as 出库日期,num as 数量,
price as 单价,num*price as 总金额,name as 会员,remark as 备注
from sell,huiyuan,product
where sell.id_product=product.id and sell.id_huiyuan=huiyuan.id
FlySQL 2011-06-16
  • 打赏
  • 举报
回复
select c.brand as 品牌,c.title as 商品名称,
a.selldate as 出库日期,a.num as 数量,a.price as 单价,a.num*a.price as 总金额,
b.name as 会员,a.remark as 备注
from sell a
left join huiyuan b on a.id_huiyuan=b.id
left join product c on a.id_product=c.id
che0922 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xb06620422 的回复:]
SQL code

select brand as 品牌,title as 商品名称,selldate as 出库日期,num as 数量,price as 单价,sum(price) as 总金额,name as 会员,remark as 备注 from sell
inner join huiyuan a on id_huiyuan=a.id
inner join product b ……
[/Quote]

from sell,huiyuan,product
就相当与内连接吧

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧