2
數和組我有這個工作查詢MySQL的加入,由多個數據庫
SELECT t1.id as stockid, t1.description as stockdescription, t2.inkoop as price , COUNT(t2.inkoop) as cnt,
(t2.inkoop * COUNT(t2.inkoop)) as totalamount
FROM database1.table_products t1
LEFT JOIN database1.table_stock t2 ON t1.id = t2.stock_id
WHERE 1
GROUP BY t2.inkoop
ORDER BY t1.id ASC
1個數據庫,2個表: T1是產品的「說明」與IDS和說明 T2數據庫是股票,這有很多的產品,什麼樣的價格(購買)和STOCK_ID
Output:
id stockdescription price cnt totalamount
1 Product1 1067 15 16005
1 Product1 1290 103 132870
2 Product2 2750 70 192500
3 Product3 500 0 0
引用但現在我有這第二數據庫(DATABASE2)與第二庫存表(stock2)(完全相同的結構database1.table_stock)
我如何改變我的查詢,所以我也可以添加'cnt2'並將總數改爲我的結果?
Like this:
id stockdescription price cnt cnt2 totalcnt totalamount
1 Product1 1067 15 0 15 16005
1 Product1 1290 103 0 103 132870
2 Product2 2750 70 5 75 206250
3 Product3 500 0 4 4 2000