国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

SQL數(shù)據(jù)排序 (轉(zhuǎn)貼)

2024-07-21 02:12:20
字體:
供稿:網(wǎng)友

--測試表
create table test(f1 char(10), f2 char(10))

--插入數(shù)據(jù)
insert into test
select 'a' f1, '1' f2
union
select 'b' f1, '2' f2
union
select 'c' f1, '4' f2
union
select 'd' f1, '3' f2
union
select 'e' f1, '4' f2
union
select 'f' f1, '5' f2
union
select 'g' f1, '4' f2
union
select 'h' f1, '7' f2
union
select 'i' f1, '9' f2

---排名次
--方法1
select a.*,(select count(*) from test b where b.f2>a.f2)+1 as minci from test a order by minci
--方法2
select id = identity (int, 0, 1), f1, f2 into #t from test order by f2 desc
select a.f1, a.f2, a.id + 1 - cast(id - cc - minn as char(10)) as [名次]
from #t a, (select f2, cc, minn from (select f2, count(*) as cc, min(id) - count(*) as minn from #t group by f2) t) b
where a.f2 = b.f2
order by a.f2 desc

--刪除表
drop table #t
drop table test

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂昌县| 钟山县| 建阳市| 宁海县| 利辛县| 陆良县| 济源市| 清远市| 和政县| 铜川市| 遂昌县| 池州市| 寿光市| 新巴尔虎右旗| 龙陵县| 临漳县| 桓仁| 汉中市| 南靖县| 扎囊县| 德安县| 万源市| 伊吾县| 新邵县| 德保县| 兴安县| 博乐市| 聂拉木县| 明光市| 盐城市| 淮滨县| 南陵县| 航空| 成都市| 峡江县| 阿图什市| 沙河市| 霍林郭勒市| 天门市| 孝昌县| 安吉县|