我想在SQL里建一个视图,有三张表 ,需要从这三张表里取数据
答案:3 悬赏:70 手机版
解决时间 2021-01-16 00:53
- 提问者网友:留有余香
- 2021-01-15 04:49
我想在SQL里建一个视图,有三张表 ,需要从这三张表里取数据
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-01-15 06:15
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
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
全部回答
- 1楼网友:动情书生
- 2021-01-15 07:37
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
)
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
)
- 2楼网友:一叶十三刺
- 2021-01-15 07:18
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
因为没有具体的表环境,无法实测。
希望你能看懂上面的关键的代码,然后自个去学会相关关键词的意义,理解后再去调试。追问哎呀 需要啊 那个 xiaoshoue=quantity*discountprice啊。。abbrev这个也是需要的啊。。 建的视图 要四个属性啊 customer_id 后面不就是abbrev么。。而且建立视图怎么着也得create view 吧。。不用么?追答那就把前面两个减号去处即可。追问
这是为什么啊?
追答SELECt
--quantity,discountprice,abbrev, --这三个不需要么?
customer_id,checkdate,SUM(xiaoshoue)
FROM (
SELECt
A.checkid,A.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
这样就好了。
--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
因为没有具体的表环境,无法实测。
希望你能看懂上面的关键的代码,然后自个去学会相关关键词的意义,理解后再去调试。追问哎呀 需要啊 那个 xiaoshoue=quantity*discountprice啊。。abbrev这个也是需要的啊。。 建的视图 要四个属性啊 customer_id 后面不就是abbrev么。。而且建立视图怎么着也得create view 吧。。不用么?追答那就把前面两个减号去处即可。追问
这是为什么啊?
追答SELECt
--quantity,discountprice,abbrev, --这三个不需要么?
customer_id,checkdate,SUM(xiaoshoue)
FROM (
SELECt
A.checkid,A.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
这样就好了。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯