我在查詢中使用了16個表,並試圖通過應用以下新更改來優化查詢。因此,我們不能使用group或union子句,因爲由於性能問題而無法應用於現有查詢。刪除條件重複值
我正在尋找通過排名/計數/排數分區意味着行級解決方案,如果可能的話。
select * FROM (
SELECT 'HA' as CODE,0 AS SR FROM DUAL UNION ALL
SELECT 'HA' as CODE,0 AS SR FROM DUAL UNION ALL
SELECT 'OF' as CODE,0 AS SR FROM DUAL UNION ALL
SELECT 'AC' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'OF' as CODE,0 AS SR FROM DUAL UNION ALL
SELECT 'OF' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'OF' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'XY' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'XY' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'HA' as CODE,1 AS SR FROM DUAL UNION ALL
SELECT 'OF' as CODE,1 AS SR FROM DUAL)
ORDER BY SR
隨着上述查詢的示例數據欲:
- 保持所有行,其中SR = 0
- 刪除SR = 1行,其中代碼值中存在(SR = 0)
例如,SR = 1的「AC」行被包括在內,因爲不存在SR = 0的「AC」行;並且SR = 1的「HA」行被刪除,因爲存在SR = 0的「HA」行。
所需輸出這樣的數據:
HA 0
OF 0
HA 0
OF 0
XY 1
XY 1
AC 1
謝謝Alex。你的答案正在起作用。 – sandip 2014-11-06 13:41:55