简体   繁体   English

查询以从表中选择具有特定列值的记录

[英]Query to select that records from the table having particular column value

在此处输入图片说明 [Ques description]I am having table of bills ,in this I don't want to show the records which is having Doctyp='BIL' [问题描述]我有帐单表,在此我不想显示具有 Doctyp='BIL' 的记录

BILNO        DOCTYP

1812B00001      BIL 
1812B00001      RCR 
ADVN            CN 
ADVN            DA 
ADVN            RCD 
ADVN            RCR 
ADVN            TF 
AL1707B00006    BIL 
AL1707B00006    RCR

I want my output like我希望我的输出像

BILNO   DOCTYP

ADVN    CN 
ADVN    DA 
ADVN    RCD 
ADVN    RCR 
ADVN    TF

NOT IN is one option: NOT IN是一种选择:

SQL> with test (bilno, doctyp) as
  2    (select 182, 'bil' from dual union all
  3     select 182, 'xxy' from dual union all
  4     select 111, 'abc' from dual union all
  5     select 111, 'zdv' from dual union all
  6     select 223, 'bil' from dual union all
  7     select 555, 'xzy' from dual
  8    )
  9  select *
 10  from test t
 11  where bilno not in (select bilno
 12                      from test
 13                      where doctyp = 'bil');

     BILNO DOC
---------- ---
       111 zdv
       111 abc
       555 xzy

Another is NOT EXISTS :另一个NOT EXISTS

SQL> with test (bilno, doctyp) as
  2    (select 182, 'bil' from dual union all
  3     select 182, 'xxy' from dual union all
  4     select 111, 'abc' from dual union all
  5     select 111, 'zdv' from dual union all
  6     select 223, 'bil' from dual union all
  7     select 555, 'xzy' from dual
  8    )
  9  select *
 10  from test t
 11  where not exists (select null
 12                    from test t1
 13                    where t1.bilno = t.bilno
 14                      and t1.doctyp = 'bil'
 15                   );

     BILNO DOC
---------- ---
       111 zdv
       111 abc
       555 xzy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要在python 3.7中使用Mysql查询从具有列(table_no,is_new)的表中选择记录 - Need Mysql query in python 3.7 to select records from table having column (table_no, is_new) SQL Select 查询,用于从过去 7 天对另一列具有连续相同值(真/假)的特定列中选择值 - SQL Select query for selecting values from a particular column having continuous same value(true/false) for another column for last 7 days 选择查询特定的列值 - Select query for particular column value 从具有特定值的表中获取列名 - To get column names from table having a particular value 从详细信息表中具有特定记录的主表返回记录 - Return records from master table having particular records in detail table 根据同一表中的列值从表中选择记录 - Select records from a table based on column value from same table 从选择查询仅将特定的列值分配给临时表 - assign only particular column values to a temp table from select query SQL查询以从具有重复编号的列中选择第一个值 - SQL query to select first value from a column having repeated number 更新表的多行,该表的特定列中的特定值等于从其他两个表中计算出的值 - Update multiple rows of a table having specific value in particular column equal to value calculated from two other tables 如果date列是date数据类型,则查询以从表中获取特定日期的记录 - Query to fetch records from a table, for a particular date if the date column is in date data type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM