我需要GROUP BY,即使是在有值之差爲一列由轉換爲文本的價值和需要被列入選擇列表的文本值集團通過問題
這是怎麼possibe?
SELECT col1,col2
FROM
(
SELECT col1,col2 FROM table1
UNION ALL
SELECT col1,col2 FROM table2
UNION ALL
SELECT col1,col2 FROM table3
)tbl
GROUP BY tbl.col1
,tbl.col2
這裏COL2可能會或可能不會是一個文本值或整型,如果是文本值,我需要的所有其他COL2整數轉換爲文本,並通過
做一組看到這個例子:
Table 1
-------
A B 3 C
A B var C
Table 2
-------
UNION ALL
B B 3 C
B B var C
Table 3
-------
UNION ALL
B B 3 C
B B 3 C
Result of each table should be
-------
Table 1
-------
A B var C (since there is a var in the any of the row in that column in that table)
Table 2
-------
B B var C (since there is a var in the any of the row in that column in that table)
Table 3
-------
B B 3 C (here it remains 3 since there is not value call var in any of the row in that column)
Result
------
A B var C
B B var C (since there is a var in the any of the row in that column in that table)
你能不能舉個例子? – alex 2010-10-22 12:26:48
如何處理一些樣本數據和一些樣本結果,您所追求的內容從您嘗試的查詢中不明顯。 – 2010-10-22 13:19:00
您使用的是MS-SQl-Server嗎?哪個版本? – Ice 2010-10-22 21:23:25