学校 专业 录取分浙大 计算机 600
浙大 电子 610
浙工大 文学 590
浙工大 历史 559
浙工大 文学 559
宁大 化学 500
宁大 物理 530
杭师院 计算机 500求出录取分小于591两所学校专业
浙大 电子 610
浙工大 文学 590
浙工大 历史 559
浙工大 文学 559
宁大 化学 500
宁大 物理 530
杭师院 计算机 500求出录取分小于591两所学校专业
select distinct 涓撲笟 from table where (瀛︽牎='娴欏ぇ' or 瀛︽牎='娴欏伐澶?) and luqufen<591
INSERT INTO #T
SELECT '娴欏ぇ' ,'璁$畻鏈? ,600 UNION ALL
SELECT '娴欏ぇ' ,'鐢靛瓙' ,610 UNION ALL
SELECT '娴欏伐澶? ,'鏂囧' ,590 UNION ALL
SELECT '娴欏伐澶? ,'鍘嗗彶' ,559 UNION ALL
SELECT '娴欏伐澶? ,'鏂囧' ,559 UNION ALL
SELECT '瀹佸ぇ' ,'鍖栧' ,500 UNION ALL
SELECT '瀹佸ぇ' ,'鐗╃悊' ,530 UNION ALL
SELECT '鏉笀闄? ,'璁$畻鏈? ,500SELECT *
FROM #T AS A
WHERE A.LuQuFen<591
AND XueXiao IN(SELECT DISTINCT TOP 2 XueXiao FROM #T AS B WHERE B.LuQuFen<591)
DROP TABLE #T
/*
XueXiao ZhuanYe LuQuFen
----------------------------
娴欏伐澶?鏂囧 590
娴欏伐澶?鍘嗗彶 559
娴欏伐澶?鏂囧 559
瀹佸ぇ 鍖栧 500
瀹佸ぇ 鐗╃悊 530
*/
insert into a (xx,zy,lqf)
select '娴欏ぇ','璁$畻鏈?,600
insert into a (xx,zy,lqf)
select '娴欏ぇ','鐢靛瓙',610
insert into a (xx,zy,lqf)
select '娴欏伐澶?,'鏂囧',590
insert into a (xx,zy,lqf)
select '娴欏伐澶?,'鍘嗗彶',559
insert into a (xx,zy,lqf)
select '娴欏伐澶?,'鏂囧',559
insert into a (xx,zy,lqf)
select '瀹佸ぇ','鍖栧',500
insert into a (xx,zy,lqf)
select '瀹佸ぇ','鐗╃悊',530
insert into a (xx,zy,lqf)
select '鏉笀闄?,'璁$畻鏈?,500
select xx,zy,lqf from a where xx in (select distinct top 2 xx from a where lqf<591) and lqf<591
Select top 2 * from 表名 Where 录取分<=591
我要的结果集,2所学校的专业记录,按高分到低分这样检索的
CSDN 上的乱码 ! 我还以为是我机器的问题!
insert test select '浙大', '计算机', 600
union all select '浙大', '电大', 610
union all select '浙工大', '文学', 590
union all select '浙工大', '历史', 559
union all select '浙工大', '文学', 559
union all select '宁大', '化学', 500
union all select '宁大', '物理', 530
union all select '杭师院', '计算机', 500
union all select '杭师院', '化学', 500
union all select '杭电大', '电子', 520
union all select '杭电大', '计算机', 520Select * From testSelect * From test WHere 学校 in (Select top 2 学校 From test WHERE 录取分<=591 Group By 学校)
Select * From test
WHere 学校 in (Select top 2 学校 From test WHERE 录取分<=591 Group By 学校 order by max(录取分) DESC,学校) AND 录取分<=591
借sxycgxj(云中客)数据一用Create table test (学校 varchar(10), 专业 varchar(10), 录取分 int)
insert test select '浙大', '計算机', 600
union all select '浙大', '電大', 610
union all select '浙工大', '文學', 590
union all select '浙工大', '歷史', 559
union all select '浙工大', '文學', 559
union all select '宁大', '化學', 500
union all select '宁大', '物理', 530
union all select '杭師院', '計算机', 500
union all select '杭師院', '化學', 500
union all select '杭電大', '電子', 520
union all select '杭電大', '計算机', 520select distinct a.学校,a.专业,b.录取分 from test a
join
(
select top 2 学校,max(录取分)as 录取分 from test
group by 学校
having max(录取分)<591
order by max(录取分)desc
)b on a.学校=b.学校 and a.录取分=b.录取分
order by b.录取分
学校 专业 录取分
---------- ---------- -----------
宁大 物理 530
浙工大 文學 590(2 row(s) affected)