从表中选择usign select语句 [英] retrive from table usign select statement
本文介绍了从表中选择usign select语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
create table markdetails(id int, mark int)
Insert into markdetails values(1,50),(1,60),(1,70),(2,50),(2,60),(3,50),(3,50),(4,50),(5,50),(5,60)
我需要输出
id mark
3 50
4 50
ex:id是多少只有50个id没有任何其他值。
(相同值没问题)。
id 3有两个50.显示一个足够的。
I need output
id mark
3 50
4 50
ex: what are the id have only 50 that id dont have any other values.
(same value is no problem).
id 3 have two 50. display one its enough.
推荐答案
select p1.id, p1.mark
from
(
select distinct mark, id from markdetails
where mark=50
)as p1
left outer join
(
select distinct id from markdetails
where mark<>50
)as p2
on p1.id= p2.id
where p2.id is null
谢谢老兄
插入markdetails值(1,50),(1,60),(1,70),(2,50),(2,60),(3,50),(3,50),(4,50) ),(5,50),(5,60)
i需要像这样出来
id mark
2 50
2 60
3 50
4 50
5 50
5 60
thanks dude
Insert into markdetails values(1,50),(1,60),(1,70),(2,50),(2,60),(3,50),(3,50),(4,50),(5,50),(5,60)
i need out put like this
id mark
2 50
2 60
3 50
4 50
5 50
5 60
SELECT DISTINCT ID,MARK From markdetails WHERE Mark in(50) AND ID NOT IN
( SELECT ID FROM markdetails WHERE Mark not in(50))
这篇关于从表中选择usign select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文