2
兩個表, TableA和TableB的列「filename」在兩個表中都具有相同的值。Sql Server中列值的總計數
只有數據發生的次數不同。
e.g
|###TableA#########|
|id|filename_TableA|
|01|file1 |
|02|file1 |
|03|file2 |
|04|file2 |
|05|file3 |
|06|file4 |
|## TableB ########|
|id|filename_TableB|
|01|file1 |
|02|file1 |
|03|file1 |
|04|file2 |
|05|file2 |
|06|file3 |
|07|file3 |
|08|file4 |
|09|file4 |
我需要生成一個SQL查詢,其顯示了不同的文件名以有
數和不同的文件名TOTALCOUNT的數量。
使用select count(distinct filename_TableA) as totalCount from TableA
給出文件名的TOTALCOUNT但我不能夠產生上述結果輸出的SQL查詢。
受審單個表:
select
filename_TableA,
count(filename_TableA)as filecount_TableA,
totalCount = (
select count(distinct filename_TableA) from TableA
)
from TableA
group by filename_TableA
感謝您爲我提供的答案,並在解決方案中增加了兩個列輸出(totalCount&UniqueFileCount)。 – shishir