sql查询一个表内包含某个字段值对应的三个字段的所有数据

Carrie_spinfo 2017-04-11 01:01:18
如下图,ID列指定的值对应的其他三个列相同的值包含的其他ID列全部显示

如何实现?
...全文
798 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_37013834 2017-12-05
  • 打赏
  • 举报
回复
select * from A where A.socre in( (select A.socre from A where A.Id= 77)) SQL中直接用这个可以查询出来数据,看他们写的好复杂的样子
qq_37013834 2017-12-05
  • 打赏
  • 举报
回复
select * from A where A.sour in( (select A.sour from Awhere A.UserId= 77))
二月十六 2017-04-11
  • 打赏
  • 举报
回复
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([starttime] time,[score] int,[id] int,[endtime] time)
Insert #T
select '11:12:02',5345,60,'11:34:54' union all
select '11:12:02',5345,61,'11:34:54' union all
select '11:12:02',5345,77,'11:34:54' union all
select '11:10:02',320,77,'11:33:47' union all
select '11:10:02',320,26,'11:33:47' union all
select '11:12:02',535,10,'11:34:54'
Go
--测试数据结束
SELECT a.*
FROM #T a
JOIN ( SELECT DISTINCT
starttime ,
score ,
endtime
FROM #T
WHERE id = 77
) b ON b.endtime = a.endtime
AND b.score = a.score
AND b.starttime = a.starttime



卖水果的net 2017-04-11
  • 打赏
  • 举报
回复
select * from t where source in (select source from t where id = 77)

22,209

社区成员

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

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