是不是列出未曾購買品項?
例如公司產品有一萬項,大成買過3500項,則需要列出另外未曾買過的6500項商品.
用意在於知道對此客戶的目前業務範圍,並據以探討未買其他產品的原因.
要列出大成未購買的產品SQL子句雛形如下
Select * from item where item_no not in (select DISTINCT order_item.item_no from order_item,ordertop where ordertop.orderno=order_item.orderno and ordertop.cust_no='TACHEN' );
解說:
Table
item : 產品檔
order_item : 訂單產品
ordertop : 訂單主檔
欄位
item_no 產品貨號
orderno 訂單編號
cust_no 客戶編號
select 全部欄位 from 產品檔 where 產品編號 不在右邊名單(大成買過的產品名單 ).
把大成買過的建立臨時性產品清單,但因為有些產品會重複買過,所以必須避開重複品號,方法是在SQL加 DISTINCT,
不會重複出現品號的產品清單為
select DISTINCT order_item.item_no(訂單產品貨號) from order_item,ordertop where ordertop.orderno=order_item.orderno and ordertop.cust_no='TACHEN'