我想在SQL里建一个视图,有三张表 ,需要从这三张表里取数据

2024年11月18日 20:15
有3个网友回答
网友(1):

SELECT 
    --quantity,discountprice,abbrev,  --这三个不需要么?
    customer_id,checkdate,SUM(xiaoshoue)
FROM (
    SELECT 
        A.checkid,customer_id,checkdate,
        quantity,discountprice,
        abbrev,
        quantity*discountprice AS xiaoshoue
    FROM
        CHECK A
        FULL JOIN CHECKGOODS ON A.CHECKID = B.CHECKID
        FULL JOIN customer C ON A.customer_id= C.customer_id
) TAL 
GROUP BY  
    --quantity,discountprice,abbrev, 
    customer_id,checkdate


因为没有具体的表环境,无法实测。

希望你能看懂上面的关键的代码,然后自个去学会相关关键词的意义,理解后再去调试。

网友(2):

create dpyxshou
as (
select check . customer_id customer_id1 , customer.abbrev abbrev1,check .checkdate checkdate1,quantity*discountprice xiaoshoue from
check inner join checkgoods on check .checkid=checkgoods .checkid
inner join customer on check .checkid=checkgoods .checkid

)

网友(3):

select a.customer_id,c.abbrev,b.checkdate,sum(b.quantity*b.discountprice) as xiaoshoue
from check a,checkgoods b,customer c
where a.checkid=b.checkid and a.customer_id=c.customer_id
group by a.customer_id,c.abbrev,b.checkdate