重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
select a.id,a.name,nvl(sum(b.quantity),0) quantity from a,b where a.id=b.id(+) group by a.id,a.name
创新互联公司是一家专注于网站建设、成都做网站与策划设计,南召网站建设哪家好?创新互联公司做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:南召等地区。南召做网站价格咨询:18982081108
我回答的比楼上早,忘记加group by了,呵呵
oracle中使用排名函数来完成类似的需求。
--使用ROW_NUMBER()
select * from
(
select stuID,stuName,age ,ROW_NUMBER() OVER (ORDER BY stuID desc) RN
from Student
) NewData
where RN BETWEEN 2 AND 5 or RN BETWEEN 6 AND 8
你这个问题解决了.
结果如图的形式.
SELECT MAX(DECODE(B.NO, 1, A.NUM1, NULL)) NUM1,
MAX(DECODE(B.NO, 1, A.NUM2, NULL)) NUM2,
MAX(DECODE(B.NO, 2, A.NUM1, NULL)) NUM1,
MAX(DECODE(B.NO, 2, A.NUM2, NULL)) NUM2,
MAX(DECODE(B.NO, 3, A.NUM1, NULL)) NUM1,
MAX(DECODE(B.NO, 3, A.NUM2, NULL)) NUM2,
MAX(DECODE(B.NO, 4, A.NUM1, NULL)) NUM1,
MAX(DECODE(B.NO, 4, A.NUM2, NULL)) NUM2,
MAX(DECODE(B.NO, 5, A.NUM1, NULL)) NUM1,
MAX(DECODE(B.NO, 5, A.NUM2, NULL)) NUM2
FROM TABLE1 A, TABLE2 B
WHERE A.NUM = B.NUM;
select 员工号、lastname、工资 from (
select 员工号、lastname、工资 from 表 order by 工资 desc )
where rownum=2
-- 先取并集,然后查询student2是否两条(根据id排序)
SELECT student FROM (SELECT student FROM A union SELECT student FROM B) a1,A a2 WHERE a2.student=a1.student and (SELECT count(*) FROM B GROUP BY student) = 2;
-- 或者
SELECT * FROM A a, B b WHERE a.student=b.student ORDER BY b.student HAVING COUNT(*)=2;