-- 美金和其他匯率的排列組合 SELECT a1.productSn AS productSn, b.currency AS currency, b.rate * a1.price AS price FROM cfg_product_price AS a1 CROSSJOIN cfg_currency AS b
WHERE a1.currency ='USD'
如果部分幣別已經新增過 就可以再left join自己一次 排除掉重複的部分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
SELECT c.productSn, c.currency, c.price FROM ( -- 美金和其他匯率的排列組合 SELECT a1.productSn AS productSn, b.currency AS currency, b.rate * a1.price AS price FROM cfg_product_price AS a1 CROSSJOIN cfg_currency AS b WHERE a1.currency ='USD') AS c
-- 過濾已經塞過的幣別 LEFTJOIN cfg_product_price AS a2 ON c.productSn = a2.productSn AND c.currency = a2.currency WHERE a2.currency ISNULL
SELECT c.productSn, c.currency, c.price FROM ( -- 美金和其他匯率的排列組合 SELECT a1.productSn AS productSn, b.currency AS currency, b.rate * a1.price AS price FROM cfg_product_price AS a1 CROSSJOIN cfg_currency AS b WHERE a1.currency ='USD') AS c
-- 過濾已經塞過的幣別 LEFTJOIN cfg_product_price AS a2 ON c.productSn = a2.productSn AND c.currency = a2.currency WHERE a2.currency ISNULL