数据量大概几千条左右;
假设有一表userinfo,
create talbe userinfo(
userid varchar(60) primary key,
name varchar(100) null,
....
flag int  null default('0')--状态 0表禁用,1表未激活,2表使用中
)
这表中,查询出同一帐号的所有信息,帐号的状态是使用中(2)写一个SQL可以做得到吗,如何写?
数据大概如下:
33234444 ,“小王”,......,2
33234444 ,“小王”,......,2
33234444 ,“小王”,......,2
33234444 ,“小王”,......,2
33234443 ,“小李”,......,2
33234443 ,“小李”,......,1
33234443 ,“小李”,......,0
33234442 ,“小胡”,......,1

解决方案 »

  1.   


    select * from userinfo where flag=2
      

  2.   

    select * from userinfo where flag=2
      

  3.   

    select * from userinfo where flag=2
      

  4.   

    [code=SQL][/select * from userinfo where flag=2code]
      

  5.   


    create table userinfo(
    userid varchar(60),
    name varchar(100),
    flag int null default('0')
    )
    insert into userinfo
    select 33234444,'小王',2 union all
    select 33234444 ,'小王',2 union all
    select 33234443 ,'小李',1 union all
    select 33234444 ,'小王',2 union all
    select 33234443 ,'小李',2 union all
    select 33234442 ,'小胡',2 union all
    select 33234443 ,'小李',0 union all
    select 33234444 ,'小王',2 union all
    select 33234442 ,'小胡',2select * from userinfo where flag = 2 order by name descdrop table userinfo
      

  6.   

    select * from userinfo where flag=2
    有这么查数据的吗,你以为学生啊?
    33234443帐号的其他记录状态是0,就不符合要求的。难道我没讲清楚还是理解错误?
      

  7.   

    就你给出的数据来看,你的数据表设计就有问题.你说的某帐号的其他记录状态是0,就不符合要求,可是在顶楼上并没有看到这句话.
    你的意思是这样?select * from userinfo a where not exists(select 1 from userinfo where userid=a.userid and flag<>2)
      

  8.   

    select * from userinfo where flag=2