SQL日记_1

select level,lpad(' ',level*3)||child child
from scott.hier
--where child not like '%Japan%'
start with parent is null
connect by prior child = parent
and child not like '%Japan%';

 

select * from tab group by grouping sets((tname,tabtype,clusterid),(tabtype));

 

select * from tab where tname like '&tname'; --UET%
select * from tab where tname like 'UET%';

 

select tname,(
case when tabtype='TABLE' then clusterid
else null
end
) as clusterid from tab where clusterid is not null
group by grouping sets((clusterid,tname,tabtype),(clusterid));


INSERT ALL  WHEN SAL > 10000 THEN  
                 INTO sal_history VALUES(EMPID,HIREDATE,SAL)
            WHEN MGR > 200 THEN
                 INTO mgr_history VALUES(EMPID,MGR,SAL) 
SELECT employee_id EMPID,hire_date HIREDATE, 
           salary SAL, manager_id MGR
FROM  employees WHERE  employee_id > 200;

INSERT FIRST WHEN SAL  > 25000  THEN
                 INTO special_sal VALUES(DEPTID, SAL)
              WHEN HIREDATE like ('%00%') THEN
                 INTO hiredate_history_00 VALUES(DEPTID,HIREDATE) 
              WHEN HIREDATE like ('%99%') THEN
                 INTO hiredate_history_99 VALUES(DEPTID, HIREDATE)
              ELSE 
                 INTO hiredate_history VALUES(DEPTID, HIREDATE)
SELECT department_id DEPTID, SUM(salary) SAL, MAX(hire_date) HIREDATE FROM employees GROUP BY department_id;


INSERT ALL  INTO sales_info VALUES (employee_id,week_id,sales_MON)
  INTO sales_info VALUES (employee_id,week_id,sales_TUE)
  INTO sales_info VALUES (employee_id,week_id,sales_WED)
  INTO sales_info VALUES (employee_id,week_id,sales_THUR)
  INTO sales_info VALUES (employee_id,week_id, sales_FRI)
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,sales_WED, sales_THUR,sales_FRI
FROM sales_source_data;

 select sum(getmoney),sum(paymoney) from test_test emp_x
 where getmoney=(select max(getmoney)
                        from test_test emp_y
                        where emp_x.pid=emp_y.pid 
                        and emp_x.paymoney=emp_y.paymoney);


delete from temp_dingou_s where exists(select fee_terminal_id
from t_act_mmsdz_user_info_bak1106 where PHONENO=fee_terminal_id
     and service_id='011001' and act_id='7206831')
    


    

你可能感兴趣的:(SQL日记_1)