![](/img/trans.png)
[英]How can I get the difference of two dates from different tables and generate it as a summary using SQL query?
[英]How can I get a difference of two columns in two different tables in a SELECT query
我想將以下兩個查詢合並為一個並得到不同的結果。
查詢1
SELECT SUM(col1 + col2) As total FROM tableA
查詢2
SELECT SUM(total) FROM tableB WHERE color not like '%black' and model not like 'CF%'
我想將它們合並到SELECT查詢中並獲得結果:查詢1-查詢2 =結果。 這兩個表之間都有一個“ id”作為公用鍵。 我正在使用MS SQL Server 2008
SELECT (
SELECT SUM(col1 + col2)
FROM tableA
) -
(
SELECT SUM(total)
FROM tableB
WHERE color NOT LIKE '%black'
AND model NOT LIKE 'CF%'
) AS result
用兩個查詢作為列進行外部選擇。
就像是
SELECT(Query1)-(Query2)為Diff
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.