jobposition表 jobinfo表
id pid name needmajorids
22 -1 营销学 -1
23 22 营销管理专业 22
24 22 营销xxx专业 23
25 22 营销xxxx专业 26
26 -1 农业类 28
27 26 农学 27
28 26 园艺 -1
如果needmajorids 是22 则存的是id 为22的值;如果needmajorids 是23 则存的虽是id 为23的值,但我要根据根据id(23) 存其对应的pid(22)的值 ;如果needmajorids 是27 则存的虽是id 为27的值,但我要根据根据id(27) 存其对应的pid(26)的值 等,如果这样的话:此时以pid排序为 22,22,26 .最后去掉重复的取前十位!例如:专业为22,22,26,27,28,28,29,30,31,32,33,35,36 ,排序取前十位后为22,26,27,28,29,30,31,32,33,35
我现在写了一部分感觉,不知对不对:
String SELECT="select * from (select pid,num,rownum qbcRownum from (select pid , count(id) num from MajorInfo where pid in (select needmajorids from jobinfo where needmajorids!=-1 and isenable=1 and CompanyId in (select id from CompanyMember where CompMemLevelId!=1 and CompMemLevelId!=100 and MemEndDate>sysdate and isenable=1) ) group by pid order by num desc) ) where qbcRownum>0 and qbcRownum<11 order by num desc ";
帮帮忙,谢谢了,急!!!
------解决方案--------------------
------解决方案--------------------
- SQL code
SQL> select deptno,ename,sal from emp order by deptno,sal desc;
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
10 CLARK 2450
10 MILLER 1300
20 SCOTT 3000
20 FORD 3000
20 JONES 2975
20 ADAMS 1100
20 SMITH 800
30 BLAKE 2850
30 ALLEN 1600
30 TURNER 1500
DEPTNO ENAME SAL
---------- ---------- ----------
30 MARTIN 1250
30 WARD 1250
30 JAMES 950
已选择14行。
SQL> break on deptno skip 1
SQL> select deptno,ename,sal from emp order by deptno,sal desc;
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
CLARK 2450
MILLER 1300
20 SCOTT 3000
FORD 3000
JONES 2975
ADAMS 1100
SMITH 800
30 BLAKE 2850
DEPTNO ENAME SAL
---------- ---------- ----------
30 ALLEN 1600
TURNER 1500
MARTIN 1250
WARD 1250
JAMES 950
已选择14行。
SQL> break on ''
SQL>
--查出各部门薪水前三名的员工姓名、薪水。
SQL> select * from(
2 select deptno,rank() over(partition by deptno order by sal desc) rk,ename,sal
3 from emp
4 )
5 where rk <=3
6 /
DEPTNO RK ENAME SAL