select * from gzjlb where bmbm='7' or bmbm='10' or bmbm='11'上面的那种查法不管怎么样都能查出数据来,只要能查到一条都会显示
我现在想实现的是bmbm='7' , bmbm='8' , bmbm='9'如果这3个同时存在的话则显示,后则一条都不显示,要怎么弄啊求可以一次查处3条数据的方法,谢谢

解决方案 »

  1.   

    select * from gzjlb where bmbm='7' and bmbm='10' and bmbm='11'
      

  2.   

    select * from gzjlb where id in
    (
    select id from
    (
    select distinct id from gzjlb where bmbm '7'
    union all
    select distinct id from gzjlb where bmbm '10'
    union all
    select distinct id from gzjlb where bmbm '11'
    ) t group by id having count(1) = 3)
      

  3.   

    select * from gzjlb where id in
    (
    select id from
    (
    select distinct id from gzjlb where bmbm ='7'
    union all
    select distinct id from gzjlb where bmbm ='10'
    union all
    select distinct id from gzjlb where bmbm ='11'
    ) t group by id having count(1) = 3)
      

  4.   

    select * from gzjlb where id in
    (
    select id from
    (
    select distinct id from gzjlb where bmbm '7'
    union all
    select distinct id from gzjlb where bmbm '10'
    union all
    select distinct id from gzjlb where bmbm '11'
    ) t group by id having count(1) = 3)
    这种的也不能查出来啊,也是空的
      

  5.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[XTBMB]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[XTBMB]
    GOCREATE TABLE [dbo].[XTBMB] (
    [ID] [int] IDENTITY (1, 1) NOT NULL ,
    [BMBM] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
    [BMMC] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
    [PX] [int] NULL ,
    [SSLX] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL 
    ) ON [PRIMARY]
    GO
    别的不会,只能发建表的代码了,呵呵
      

  6.   

    select * from gzjlb where bmbm='7' and bmbm='8' and bmbm='9'
      

  7.   

    改7 8 9 试试select * from gzjlb where id in
    (
    select id from
    (
    select distinct id from gzjlb where bmbm ='7'
    union all
    select distinct id from gzjlb where bmbm ='8'
    union all
    select distinct id from gzjlb where bmbm ='9'
    ) t group by id having count(1) = 3)
      

  8.   

    数据是这样的 XTBMB表字段    id     bmbm
    数据     1       7
            2       8
            3       9
            4       10
            5       11
    输入7,8,9的时候查处字段    id     bmbm
    数据     1       7
            2       8
            3       9如果其中一个没有,例如7不存在则一条数据也不显示出来,相当于事务
      

  9.   


    SELECT * FROM XTBMB
    WHERE 
    (SELECT COUNT(1) FROM XTBMB WHERE BMBM in(7,8,9)) = 3
    AND (BMBM in(7,8,9))
    这样?