1樓:你好師姐
create table #a(address char(2),fenshu varchar(8))
insert into #a values ('a1','s1')insert into #a values ('a1','s2')insert into #a values ('a2','s3')insert into #a values ('a1','s7')insert into #a values ('a2','s4')insert into #a values ('a2','s8')insert into #a values ('a1','s8')insert into #a values ('a2','s9')實際語法測試 應該加上 分組條件區別,否則會有重複記錄被取出(a.address = b.address)
select * from #a a
where fenshu in (
select max( fenshu) from #a b where a.address = b.address
group by address)
2樓:匿名使用者
很容易select *
from tab t
where not exists (select 1 from tab where address = t.address and fenshu > t.fenshu)
3樓:落月
select * from 表 where address+cast(fenshu as varchar(20)) in (
select address+cast(max(fenshu) as varchar(20)) from 表 group by address)
4樓:
select id,name,address,fenshu,update from (select * ,row_number() over (partition by test3 order by test2 desc) tt from 表名) qq
where tt = 1
5樓:
select * from table
where fenshu in (
select max( fenshu) from tabegroup by address)
6樓:匿名使用者
select t.* from table_name t where t.fenshu =
(select max(tt.fenshu) from table_name tt where tt. address = t.address )
7樓:匿名使用者
select *,max(fenshu) from 表 group by address
sql查詢 分組後 每組某欄位值最大的一行所有列 200
8樓:匿名使用者
按照員工id分組,取出id值最大的一行
1、第一個方法,需要考慮id有重複值的問題,如果最大值存在重複值,那麼結果也重複。
select *
from 員工資訊變化表 t1
where id = (select max (id)from 員工資訊變化表 t2
where t1.員工id = t2.員工id)2、第二個方法:
該語句是在sql server中編寫的,應該不適用於mysq和oracle。排名函式是sql server2005中新增的功能,不適用sql server 2000
select *
from (select row_number () over (partition by 員工id order by id desc)
as row_num,
*from 員工資訊變化表) t1
where row_num = 1
sql如何查詢空值的欄位,sql資料庫查詢中,空值查詢條件怎麼寫?
小凝聊娛樂 sql查詢空值的欄位寫法 select a.欄位 from student a where a.欄位 like student為表名 查詢類似空值的寫法 1 查詢名稱有退格鍵 select from t bd item info where charindex char 8 item n...
sql語句判斷一張表的某欄位為空,然後查詢另外一張表的資料,怎麼寫
樓上那個不行,應該是a沒有再找b 而不是連線2個表一起找樓主你的 的問題出在when id is null 你都輸入id 10289了 id怎麼會空?應該是select case when a.name is null thenb.name else a.name end name from sel...
關於sql查詢,想從很多表中查詢欄位值
select q.條碼 case when isnull a.a站點,then t else f end 是否經過a站點 case when isnull b.b站點,then t else f end 是否經過b站點 from 條碼錶 q left join a a on a.條碼 q.條碼lef...