+ -
当前位置:首页 → 问答吧 → 求一个SQL语句

求一个SQL语句

时间:2011-12-26

来源:互联网

数据量大概几千条左右;
假设有一表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

作者: qq598235031   发布时间: 2011-12-26

SQL code

select * from userinfo where flag=2

作者: geniuswjt   发布时间: 2011-12-26

SQL code
select * from userinfo where flag=2


作者: kingtiy   发布时间: 2011-12-26

select * from userinfo where flag=2

作者: fredrickhu   发布时间: 2011-12-26

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

作者: SylarZhou   发布时间: 2011-12-26

SQL code

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 ,'小胡',2

select * from userinfo where flag = 2 order by name desc

drop table userinfo

作者: ju523756055   发布时间: 2011-12-26

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

作者: qq598235031   发布时间: 2011-12-26

显然是你没讲清楚撒 谁知道你需要什么结果?

作者: fredrickhu   发布时间: 2011-12-26

就你给出的数据来看,你的数据表设计就有问题.你说的某帐号的其他记录状态是0,就不符合要求,可是在顶楼上并没有看到这句话.
你的意思是这样?

SQL code
select * from userinfo a where not exists(select 1 from userinfo where userid=a.userid and flag<>2)

作者: qianjin036a   发布时间: 2011-12-26

select * from userinfo where flag=2

作者: TravyLee   发布时间: 2011-12-26