select a.FTranType 訂單型別 ,a.fbillno 訂單號,a.fdate 日期,'供應商' 往來單位,b. fitemid 代碼,b.fname名稱,b.fmodel 規格, c.fqty 數量 from poorder a,t_icitem b,poorderentry c
union all
select a.FTranType 訂單型別, a.fbillno 訂單號,a.fdate 日期,'客戶' 往來單位,b. fitemid 代碼,b.fname名稱,b.fmodel 規格, c.fqty 數量 from seorder a,t_icitem b,SEOrderEntry c
uj5u.com熱心網友回復:
只要列數相同就可以用union all 這樣子出現重復資料不會自動洗掉,對于你的例子有一列的列名是poorderentry c而不會用SEOrderEntry cuj5u.com熱心網友回復:
union all 要求不高,只要兩個查詢的列數及對應列的資料型別一致即可。但你的寫法是有問題,from 表1, 表2 這種寫法容易產生嚴重的錯誤,也不是微軟推薦的規范寫法,不要用。
兩個表的關聯,要用 join on 的形式。
你用逗號,就很容易丟失關聯條件。
瞎弄,最后肯定會出邏輯錯誤。
SELECT a.FTranType 訂單型別,
a.fbillno 訂單號,
a.fdate 日期,
'供應商' 往來單位,
b. fitemid 代碼,
b.fname名稱,
b.fmodel 規格,
c.fqty 數量
FROM poorder a INNER JOIN t_icitem b ON xx=yy
INNER JOIN poorderentry c ON xx=zz
UNION ALL
SELECT a.FTranType 訂單型別,
a.fbillno 訂單號,
a.fdate 日期,
'客戶' 往來單位,
b. fitemid 代碼,
b.fname名稱,
b.fmodel 規格,
c.fqty 數量
FROM seorder a INNER JOIN t_icitem ON xx=yy
INNER JOIN SEOrderEntry c ON xx=zz
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/52369.html
標籤:基礎類
上一篇:vscode.環境問題
下一篇:Flink入門寶典(詳細截圖版)
