sql语句如何写才好?

CppFile 2009-03-13 03:59:10
有3个表分别是:
member表(member_no,card_no)

goods表(goods_no,member_no)

notaccess表(goods_no,member_no)

其中notaccess表中的记录是这样的:

goods_no member_no
1 空
2 0008
3 0009
2 0010


如果member_no为空,则表示该商品对所有的会员都不能销售,如果不空,则表示该商品对该会员不能销售


现在假设member=0010,要求获取改会员所能销售的商品列表即goods_no
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kavoe 2009-03-14
  • 打赏
  • 举报
回复
你的goods表结构好像有点问题,怎么和下面的notaccess结构相同呢?另外既然是goods表,应该有商品名把


按我的理解写的

select goods_name(你的商品名字段) from goods a

where exists
(select 1 from notaccess b where a.goods_no = b.goods_no
and b.member_no is not null and b.member_no <> '0010')


会员编号你给了,因此也就不用关联会员表了
Andy__Huang 2009-03-13
  • 打赏
  • 举报
回复
select a.*
from notaccess a
left join goods b on a.golds_no=b.golds_no
where a.member_no is not null and a.member_no<>'0010'



dawugui 2009-03-13
  • 打赏
  • 举报
回复
select m.goods_no from goods m , member n where m.member_no = n.member_no and n.member_no = '0010' and m.goods_no not in 
(select a.goods_no from notaccess a, member b where (a.member_no = b.member_no and b.member_no = '0010') or a.member_no = '空')
dawugui 2009-03-13
  • 打赏
  • 举报
回复
select m.goods_no from goods m , member n where m.member_no = n.member_no and n.member_no = '0010' and m.goods_no not in 
(select a.goods_no from notaccess a, member b where a.member_no = b.member_no or a.member_no = '空')
you_tube 2009-03-13
  • 打赏
  • 举报
回复
不知道在说什么,帮顶

34,588

社区成员

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

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