视图内的子查询

时间:2018-04-06 19:17:04

标签: sql view subquery between

我试图创建一个视图,列出2016年8月14日到2016年8月23日期间创建的所有订单的所有订单ID,订单日期,发货日期和公司名称。问题说需要有一个视图中的子查询,但我不确定应该在哪里或什么。以下是我到目前为止的情况:

    CREATE VIEW LAB9_VIEW
    AS
    SELECT orderid, orderdate, shippeddate, companyname
    FROM orders JOIN customers ON orders.customerid = customers.customerid
    WHERE (SELECT * from orders.orderdate) BETWEEN '2016-08-14' AND '2016- 
    08-23')
    WITH READ ONLY;

2 个答案:

答案 0 :(得分:0)

查看代码,可以在JOIN中使用AND子句

CREATE VIEW LAB9_VIEW
AS
SELECT orderid, orderdate, shippeddate, companyname
FROM orders JOIN customers ON orders.customerid = customers.customerid
        AND orders.orderdate BETWEEN '2016-08-14' AND '2016- 08-23'

WITH READ ONLY;

答案 1 :(得分:0)

视图中的子查询将是这样的:

CREATE VIEW LAB9_VIEW
AS
SELECT orderid, orderdate, shippeddate, companyname
FROM orders JOIN customers ON orders.customerid = customers.customerid
WHERE orders.orderdate in (SELECT orderdate from orders where orderdate 
BETWEEN '2016-08-14' AND '2016-08-23')
WITH READ ONLY;