求教一个sql语句的写法

等等 2012-04-17 12:19:42
我这里有两个表AB。
A表中有一列的列的内容是"Brand",另外有一个列是‘status’,其中Brand有很多不同内容
B表中有一列的列的内容是"Brand",其中Brand有很多不同内容

如何来查询B中Brand匹配[A中status='onsale'的所有brand值]的所有行个数呢?

谢谢大家!
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2012-04-17
  • 打赏
  • 举报
回复


select * from B where exists(select 1 from A where 列1=b.列1 and Status='onsale')
gogodiy 2012-04-17
  • 打赏
  • 举报
回复
大版这么晚还在线啊
shuohuameijiang 2012-04-17
  • 打赏
  • 举报
回复
select * from a,b where a.brand=b.brand and a.brand.status='onsale'
APHY 2012-04-17
  • 打赏
  • 举报
回复

SELECT * FROM B WHERE BRAND IN(SELECT BRAND FROM A WHERE status='onsale')

SELECT T2.* FROM A T1,B T2 WHERE T1.BRAND=T2.BRAND AND T1.status='onsale'
  • 打赏
  • 举报
回复
+1
[Quote=引用 1 楼 的回复:]

SQL code


select * from B where exists(select 1 from A where 列1=b.列1 and Status='onsale')
[/Quote]

34,590

社区成员

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

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