根据condation选择行 [英] select rows based on condation

查看:97
本文介绍了根据condation选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

需要你的帮助。



我有一张桌子..



PK身份状态

1 1 01

2 1 02

3 2 01

4 3 01

5 3 02



我想选择状态等于01的thoese记录,但状态为!= 02,其id相同。

预期产量将是..



Pk id状态

3 2 01

Hi All
Need your help.

I have one table below..

PK id status
1 1 01
2 1 02
3 2 01
4 3 01
5 3 02

I want to select thoese records where status equal to 01 but status !=02 whose id is same.
the expected output will be..

Pk id status
3 2 01

推荐答案

试试这个:
SELECT  *
FROM    Table1 t1
WHERE   status = '01'
    AND NOT EXISTS
    (
    SELECT  1
    FROM    table1 t2
    WHERE   status = '02'
        AND t1.id = t2.id
    )






检查这个...



Hi,

Check this...

Select * from table_1 Where status = '01' and id not in (SELECT distinct id from table_1 Where status = '02')





希望这会对你有所帮助。



干杯



Hope this will help you.

Cheers


这篇关于根据condation选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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