国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 宜州市| 肇源县| 怀仁县| 略阳县| 巴东县| 睢宁县| 祁连县| 萨迦县| 新昌县| 疏附县| 洪湖市| 那曲县| 类乌齐县| 宜春市| 穆棱市| 都江堰市| 商洛市| 繁峙县| 岳普湖县| 石门县| 德令哈市| 内江市| 乾安县| 武邑县| 蓬溪县| 合川市| 定日县| 建水县| 巫溪县| 瓮安县| 恩施市| 焦作市| 余庆县| 合肥市| 阜城县| 浦城县| 凤庆县| 长阳| 北京市| 赣州市| 松江区|