高手帮忙写条sql语句!!!
查 询 user表中 所有的 数据
但不能 让username 有重复的
谢谢了
[解决办法]
select username,max(字段1) as 字段1,max(字段2) as 字段2...
from user
group by username
[解决办法]
create table a(name varchar(10), scot int)
insert a
select 'a ',1 union all
select 'b ',1 union all
select 'c ',1 union all
select 'd ',2 union all
select 'e ',2
select * from a t where [name] = (select max([name]) from a where t.scot=scot)
[解决办法]
ls的取出来的数据可能不准啊!
我给的只是一个例子
[解决办法]
假设--
表 :user
字段:name
name
aa
aa
bb
ff
得到
name
aa
bb
ff
不知道LZ是不是这么意思。如果是的话sql如下:
Select * from user as a where not exists
(select * from yonghu where a.name=user.name and a.id <user.id )
[解决办法]
select
u.*
from
user u
where
username not in(select username from user group by username having count(*)> 1)
[解决办法]
declare @a table (name varchar(10), scot int)
insert @a
select 'a ',1 union all
select 'a ',1 union all
select 'b ',1 union all
select 'c ',2 union all
select 'e ',2
select * from @a a
where (select count(1) from @a where name=a.name)=1
(5 行受影响)
name scot
---------- -----------
b 1
c 2
e 2
(3 行受影响)
[解决办法]
是不是这样,a有两条记录以上不显示,只显示name只有一条的记录