三个表,一对多查询:已经商品名,找到多个订单,要求返回订单对应的客户名称

cnhxjtoa 2008-02-21 11:49:40
订单表A. ID为订单号,NAME为客户名称
订单商品表B ID为订单号, NAME为商品名称
产品名称表C ID产品编号,NAME为商品名称

求:根据移动表C中的任意一条记录,返回所有购买此商品的客户名称的SQL语句
...全文
212 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
JiangHongTao 2008-02-21
  • 打赏
  • 举报
回复
select a.name from 订单表A a,订单商品表B b
where a.ID=b.id and b.name='商品名称'
-------------------------------------------------
哈哈,顶一个
pt1314917 2008-02-21
  • 打赏
  • 举报
回复

select a.name from 订单表A a,订单商品表B b
where a.ID=b.id and b.name='商品名称'
byronqiji 2008-02-21
  • 打赏
  • 举报
回复
select * from a where id in (
select id from b where name in (
select name from c where id in (ID产品编号)))
liangCK 2008-02-21
  • 打赏
  • 举报
回复
select a.name
from 订单表 a ,订单商品表 b,产品名称表 c
where a.订单号=b.订单号 and b.商品名称=c.商品名称 and c.商品名称='CPU'
pt1314917 2008-02-21
  • 打赏
  • 举报
回复
订单商品表B ID为订单号, NAME为商品名称
----------------------
多嘴一句,这个订单商品表B中的name字段,是否改为ID产品编号更好呢?

------这样??

select name from 订单表A a,订单商品表B b
where a.ID=b.id and b.name='商品名称'

liangCK 2008-02-21
  • 打赏
  • 举报
回复
select a.name
from 订单表 a ,订单商品表 b,产品名称表 c
where a.订单号=b.订单号 and b.商品名称=c.商品名称 and c.产口编号='1254'

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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