创建或替换视图

时间:2014-11-30 21:17:14

标签: sql oracle greatest-n-per-group

您好我在SQL中创建替换视图时遇到问题。 我要做的是创建或替换一个视图,显示本周前5个销售产品和超过5天没有发货ID的发票。这就是我到目前为止所拥有的。任何帮助将不胜感激

CREATE OR REPLACE VIEW helper.manager_view AS 
SELECT Inv_Num, Line_Num, P_Code
FROM helper.LINE
WHERE 
UNION 
SELECT 
Inv_DATE AS ENTRY_DATE,  
FROM helper.INVOICE 
WHERE Inv_Date >
ORDER BY Inv_Date 

1 个答案:

答案 0 :(得分:2)

假设您的数据库支持CREATE OR REPLACE VIEW(并非所有数据库都支持),您有几个问题,如下所示:

CREATE OR REPLACE VIEW helper.manager_view AS 
    SELECT Inv_Num, Line_Num, P_Code
    FROM helper.LINE
    WHERE 
----------^ Uh, what goes here?
    UNION 
    SELECT Inv_DATE AS ENTRY_DATE,  
-----------^ Same number and types of arguments as in the first `SELECT`
    FROM helper.INVOICE 
    WHERE Inv_Date >
---------------------^ Uh, what goes here?
    ORDER BY Inv_Date
-------------^ There is no `Inv_Date` in the first `SELECT`