记录一
查询顺序
FROM,WHERE,GROUP BY,SELECT,ORDER BY
(select 只的是查询的指定列)
记录二
子查询
语句理解
select m.*,
(
SELECT o.name orgname
from TREE T, ORGO
where T.PID <> -1 AND T.DAID = O.ID(+) and rownum = 1
start with t.id = m.defpos connect by prior t.PID = t.id
) dename
from (select max(e.cnname) as name,
max(e.defpos ) as defpos ,
max(decode(e.isdel, ‘Y’,‘离职’,‘在职’)) as islizhi,
i.dr as empid,
t.mony as mony,
t.year as biyear,
max(decode(t.clomnt, ‘1’, t.money, null)) as mon1,
max(decode(t.clomnt, ‘2’, t.money,null)) as mon2,
max(decode(t.clomnt,‘3’,t.money,null)) as mon3,
max(decode(t.clomnt,‘4’,t.money,null)) as mon4,
max(decode(t.clomnt, ‘5’, t.money,null)) as mon5,
max(decode(t.clomnt, ‘6’, t.money, null)) as mon6,
max(decode(t.clomnt,‘7’,t.money,null)) as mon7,
max(decode(t.clomnt,‘8’,t.money,null)) as mon8,
max(decode(t.clomnt,‘9’,t.money,null)) as mon9,
max(decode(t.clomnt,‘10’,t.money, null)) as mon10,
max(decode(t.clomnt,‘11’,t.money,null)) as mon11,
max(decode(t.clomnt,‘12’,t.money,null)) as mon12,
sum(t.rebsmoney) as amount
from sub t, ins i, emp e
where i.inid = t.instid and i.dr = e.eid
group by i.dr, t.mony,t.year
order by i.dr) m