Oracle的table()函數(shù)是一種將集合類型轉(zhuǎn)換為關(guān)系表的方法,它可以在復(fù)雜查詢中發(fā)揮作用
示例:計算每個部門的員工平均工資,并按部門排序。
SELECT department_id, AVG(salary) OVER (PARTITION BY department_id) as avg_salary
FROM table(employees);
示例:將員工的工資信息按月份進行展示。
SELECT *
FROM table(employees)
PIVOT (
SUM(salary) FOR month IN ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
);
示例:查詢組織結(jié)構(gòu)中的所有經(jīng)理及其直接下屬。
SELECT employee_id, manager_id, level
FROM table(employees)
CONNECT BY PRIOR employee_id = manager_id
START WITH employee_id = 100;
示例:查詢平均工資高于部門平均工資的員工。
SELECT employee_id, salary
FROM table(employees)
WHERE salary > (
SELECT AVG(salary)
FROM table(employees) e2
WHERE e2.department_id = employees.department_id
);
總之,在復(fù)雜查詢中,table()函數(shù)可以與多種SQL操作結(jié)合使用,實現(xiàn)更高效、更靈活的數(shù)據(jù)處理和分析。