2012-02-29 57 views
-3

我當前的查詢拆分和COUNT是這樣的:如何通過GROUP BY

SELECT Discipline, COUNT(*) Cnt FROM [xxx].[dbo].[ScanDoc] 
WHERE Discipline <> '' 
GROUP BY Discipline 

的結果是這樣的..

 
Discipline           Cnt 
Advanced Material Science       1 
Advanced Material Science;#Chemical Science   2 
Advanced Material Science;#Engineering Science  1 
Agriculture Science         1 
Business and Economics        3 
Computer Sciences and ICT       1 
Computer Sciences and ICT;#Business and Economics 1 
Engineering Science         3 
Health and Medical Science       3 
Health and Medical Science;#Life Science   2 
Humanities and Social Science      9 
Life Science          1 

所以我想是分裂多個值。 .sifoo請告訴我的方式..

我想造成這樣

 
Discipline           Cnt 
Advanced Material Science       4 
Chemical Science          2 
Engineering Science         1 
Agriculture Science         1 
Business and Economics        3 
Computer Sciences and ICT       2 
Business and Economics        1 
Engineering Science         3 
Health and Medical Science       5 
Humanities and Social Science      9 
Life Science          3 

你看到結果之間的不同嗎?

+0

你是什麼意思?請根據您的數據提供結果示例。 – 2012-02-29 02:19:34

+0

請參考上面的問題...我想分開'紀律'並算數... TQ – 2012-03-01 03:52:49

回答

0

不幸的是,在SQL Server中沒有SPLIT函數,所以最好的辦法是創建一個SPLIT函數,然後從聯合查詢中調用它,先採取第一部分,第二部分採用Discipline的後半部分!

+0

謝謝...我找到了soltuion .. – 2012-08-01 03:15:04