有幾種解決方案,您可以:
間斷FULL OUTER JOIN
SELECT
SUM(MYTABLE.ID) as theSum,
COUNT(DISTINCT MYTABLE.SOMEVALUE) as theCount,
COUNT(DISTINCT MYOTHERTABLE.SOMEOTHERVALUE) as theOtherCount
FROM MYTABLE
FULL OUTER JOIN MYOTHERTABLE ON 1=0
UNION
兩個查詢和 '每列的查詢' 針對單個記錄表離開列的其他表空
SELECT
MAX(theSum) as theSum,
MAX(theCount) as theCount,
MAX(theOtherCount) AS theOtherCount
FROM (
SELECT
SUM(ID) as theSum,
COUNT(DISTINCT SOMEVALUE) as theCount,
NULL as theOtherCount
FROM MYTABLE
UNION ALL
SELECT
NULL,
NULL,
COUNT(DISTINCT SOMEOTHERVALUE)
FROM MYOTHERTABLE
)
查詢(例如RDB$DATABASE
)
每桌+交叉
CTE加入
WITH query1 AS (
SELECT
SUM(ID) as theSum,
COUNT(DISTINCT SOMEVALUE) as theCount
FROM MYTABLE
),
query2 AS (
SELECT
COUNT(DISTINCT SOMEOTHERVALUE) as theOtherCount
FROM MYOTHERTABLE
)
SELECT
query1.theSum,
query1.theCount,
query2.theOtherCount
FROM query1
CROSS JOIN query2
可能有一些更多的解決方案。你可能想問問自己,爲了得到這個數據是否值得花費一個(令人費解的,難以理解的)單個查詢來獲得這些數據:兩個查詢是足夠的,更容易理解的,並且在大數據集的情況下:兩個單獨的查詢可能會更快。
我不確定你想在這裏實現什麼。 –
只是想運行一個報告。不過,我希望從另一個表中再做一次(不同的)。選擇 SUM(IMG_RAM), SUM(IMG_CORE_COUNT), COUNT(DISTINCT(IMG_NAME)) 從圖像中 – user3328740
一切都是可能的,但你通常只查詢兩個表,如果他們有邏輯關係,而這種關係可能(需要)影響計數的結果。 –