我有兩個查詢返回雙精度值的單柱:司在SQL查詢語句
(SELECT scale
FROM (SELECT title,
scale,
dense_rank() OVER (PARTITION BY title
ORDER BY scale ASC) AS r
FROM signatures) t
WHERE r = 1)
...和:
(SELECT scale
FROM (SELECT scale,
dense_rank() OVER (PARTITION BY title
ORDER BY scale ASC) AS r
FROM signatures) t
WHERE r = 2)
我想選擇第一個查詢( Q1)除以第二個查詢(Q2)。即,(Q1的第1行)/(Q2的第1行)。並繼續沿着其餘的行。
我曾嘗試:
SELECT ((SELECT scale
FROM (SELECT title,
scale,
dense_rank() OVER (PARTITION BY title
ORDER BY scale ASC) AS r
FROM signatures) t
WHERE r = 1)
/
(SELECT scale
FROM (SELECT scale,
dense_rank() OVER (PARTITION BY title
ORDER BY scale ASC) AS r
FROM signatures) t
WHERE r = 2)
)
但有沒有運氣。 任何人都可以看到一種方法來做到這一點?我可以分別發送這兩個查詢,然後運行一個循環並分割元素,但這不適用於半大記錄集。
此外,它應該不重要,但我使用PostgreSQL。
你知道如果處理關係,`DENSE_RANK`會返回相同的值嗎?例如,您可以將三個實例並列第二名,這會導致您的分區發生悲傷...... – 2011-01-13 16:47:42
@OMG。好的,但是如果我單獨運行查詢,我會得到正確的列結果。是不可能在一個陳述中分開這兩個? – Brett 2011-01-13 17:01:28