????????SQL???????Top??Apply
???????????? ???????[ 2015/12/8 11:44:14 ] ?????????????
?????????
???????????????????????num????????
????--??????
/*
bj xh name cj
---------- ---- ---------- -----------
??? A006 A6 100
??? A005 A5 99
??? A001 A1 89
??? A002 A2 89
???? B001 B7 100
???? B001 B6 99
???? B001 B9 97
???? B001 B8 90
???? B001 B5 88
*/
-- ?????????
declare @student table(
---?????
bj varchar(10)??
-- ??
xh char(4)??
-- ???
name varchar(10)??
-- ????
cj int)
-- ???
declare @tj table(
---????
bj varchar(10)??
-- ??
num int)
-- ???? ?????????????????????num????????
set nocount on
-- ??????????
insert @student select '???' ??'A001'??'A1'??89
insert @student select '???' ??'A002'??'A2'??89
insert @student select '???' ??'A003'??'A3'??59
insert @student select '???' ??'A004'??'A4'??80
insert @student select '???' ??'A005'??'A5'??99
insert @student select '???' ??'A006'??'A6'??100
insert @student select '???' ??'A007'??'A7'??82
insert @student select '????' ??'B001'??'B1'??19
insert @student select '????' ??'B001'??'B2'??81
insert @student select '????' ??'B001'??'B3'??69
insert @student select '????' ??'B001'??'B4'??86
insert @student select '????' ??'B001'??'B5'??88
insert @student select '????' ??'B001'??'B6'??99
insert @student select '????' ??'B001'??'B7'??100
insert @student select '????' ??'B001'??'B8'??90
insert @student select '????' ??'B001'??'B9'??97
insert @tj select '???'??3
insert @tj select '????'??5
?????ο?SQL??
-- 2005.T-SQL
select t.bj??s.xh??s.name??s.cj
from @tj t
cross apply (
SELECT TOP(t.num)
with ties
-- ?? with ties????????4?????2??????е???????
xh??name??cj
from @student
where t.bj=bj
-- ??where ?????????? inner join ???????????? cross join
order by cj desc
)s
order by case when t.bj='???' then 1 else 2 end asc??s.cj desc??s.xh asc
---????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
???????????SQL???SQL??й????е????????????mysql?????????????SQL??????????????mysql????? distinct?÷?MySQL?н???????????з??Mysql????????????????sql server 2000??????????????MySQL Cluster??δ??????????????SQL Server???????????????????λ?????PHP??SQL????????????????????????????SQL??????????SQLд?????SQL Server????????????????????????????????????SQL?????Pythonд???NoSQL?????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????