sql的A表筛选后怎样根据两张表相同的ID关联B表呢?

chauncy_win 2021-02-22 03:23:24
sql的A表筛选后怎样根据两张表相同的ID关联B表呢?



例如:

A表:id
select * from dweller where buy ='否' and (type='第一'or type='第二'or type='第三')


B表:id
...全文
239 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
吉普赛的歌 2021-02-23
  • 打赏
  • 举报
回复
--1.
SELECT * 
FROM 
(
	select * from dweller where buy ='否' and (type='第一'or type='第二'or type='第三')
) AS A
INNER JOIN B
    ON A.id=B.id
    
    
--2. 推荐写法
select * from dweller AS A
	INNER JOIN B ON A.id=B.id 
where A.buy ='否' and (A.type='第一'or A.type='第二'or A.type='第三')

22,207

社区成员

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

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