我只需要过滤那些对id只有'N'的行 [英] I need to filter only that rows which is having only 'N' against the id

查看:105
本文介绍了我只需要过滤那些对id只有'N'的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

id Generated

=========================

1 N

1 N

1 Y

2 Y

2 Y

3 N

3 N

3 N

4 N

5 Y






来自上表的
我只需要那个行所有'N'的ID。



i尝试通过

从表中选择不同的id,其中id不在(从表中选择不同的id,其中generate ='Y')



表有这么多记录,当我运行我的查询时,它给出了temp内存不足的错误(dnt记住确切的单词)



你能不能请提供了一些其他方法来实现输出?

id Generated
=========================
1 N
1 N
1 Y
2 Y
2 Y
3 N
3 N
3 N
4 N
5 Y



from the above table i need only that id which is having 'N' for all its rows.

i tried by
select distinct id from table where id not in (select distinct id from table where generated='Y')

table is having so many records, when i run my query its gives error that temp is out of memory(dnt remember exact words)

Could you please provide me some other way to to achieve the output?

推荐答案

SELECT DISTINCT
    id
FROM
    your_table
WHERE
    col = 'N'
EXCEPT
SELECT
DISTINCT
    id
FROM
    your_table
WHERE
    col = 'y'


您好,



查看此...



Hi,

Check this...

select * from your_table where id not in (select id from your_table where generated='Y' )







希望这会对你有所帮助。



干杯




Hope this will help you.

Cheers


试试这个



Try this

select * from #temp t1 where Generated='N'
and not exists
(select ID from #temp t2 where Generated='Y' and t1.Id=T2.Id)







并且在选择后的词语中应用明确的这样您的查询处理不会花费太多时间。




and do apply distinct on selection afterwords so that your query processing does not take much time.


这篇关于我只需要过滤那些对id只有'N'的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆