1
3表格產品,銷售,折扣。如何編寫在選擇查詢中使用外部表格進行計算的子查詢,我們可以以調整的方式編寫這個
create table Product (Pid Varchar2(15),Productname Varchar2(50),PriceofSingle Number(10));
Create table Disc_product(pid varchar2(15),Qty number,disc_percent number);
create table sales(salesid number(20),Pid varchar2(15),productname varchar2(40) ,qty number(10));
想要檢索產品的詳細信息。如果產品的購買數量超過disc_product表中提供的數量,則折扣百分比適用於其他編號。
我已經寫了查詢其做工精細.....的擊打它非常混亂.... 我想是有實現相同
Select s.salesid,s.pid,p.Productname,s.qty ,
(NVL((select disc_percent from disc_product where pid = s.pid and qty <s.qty),1)) as disc,
((p.priceofsingle * s.qty) * (NVL((select disc_percent from disc_product where pid = s.pid and qty <s.qty),1))) as T_price**
from sales s left join product p on S.pid = p.pid
謝謝布萊恩。在折扣表結構中,我們只有一列數量。 – shalini