我的查询位置有两个错误检查我的查询是对还是错我是Oracle新手,所以不要在意
这是SQL
SQL正在给出错误:ORA-00909: Invalid Number of Arguments
CREATE VIEW order_summery
AS
SELECT o.id,
o.order_date,(cu.first_name||' '|| cu.last_name) as customer_name
,Sum(NVL(p.price,0)) as total_amount
,Sum(NVL(p.discount_amount,0)) as discount_amount
,NVL(Sum(NVL(p.price,0),0)) - NVL(Sum(NVL(p.discount_amount,0)),0) as final_amount
FROM tbl_order o
INNER JOIN tbl_customer cu on o.customer_id = cu.id
INNER JOIN tbl_order_item oi on o.id= oi.order_id
INNER JOIN tbl_product p on oi.product_id= p.id;
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
CREATE VIEW sales_report
AS
SELECT o.id,
,o.order_date
,(cu.first_name||' '|| cu.last_name) as customer_name,
,Sum(NVL(p.price,0)) as total_amount
,Sum(NVL(p.discount_amount,0)) as discount_amount
,NVL(Sum(NVL(p.price,0),0)) - NVL(Sum(NVL(p.discount_amount,0)),0) as final_amount
,CASE o.is_deliverd WHEN 'y' THEN 'Deliverd' ELSE 'Not Deliverd' END as status
FROM tbl_order o
INNER JOIN tbl_customer cu on o.customer_id = cu.id
INNER JOIN tbl_order_item oi on o.id= oi.order_id
INNER JOIN tbl_product p on oi.product_id= p.id;
答案 0 :(得分:1)
您的问题在这里(Sum(NVL(p.price,0),0))
另外,我猜您需要使用按功能分组,因为您有总和。而且不需要nvl。
CREATE VIEW order_summery
AS
SELECT o.id,
o.order_date,(cu.first_name||' '|| cu.last_name) as customer_name
,Sum(NVL(p.price,0)) as total_amount
,Sum(NVL(p.discount_amount,0)) as discount_amount
,Sum(NVL(p.price,0)) - Sum(NVL(p.discount_amount,0)) as final_amount
FROM tbl_order o
INNER JOIN tbl_customer cu on o.customer_id = cu.id
INNER JOIN tbl_order_item oi on o.id= oi.order_id
INNER JOIN tbl_product p on oi.product_id= p.id
group by o.id, o.order_date ,cu.first_name,cu.last_name ;
对于第二个查询,删除ID后面的,
o.id,
,
答案 1 :(得分:0)
修复final_amount参数(仅需要一个NVL函数):
,Sum(NVL(p.price,0)) - Sum(NVL(p.discount_amount,0)) as final_amount