日期:2014-05-18 浏览次数:20567 次
SELECT top 10 SUM(counts) AS Number, case term when 'ACUTELY' then 'ACUTELYS' else term end as Log_Item1 FROM wf_cipin GROUP BY case term when 'ACUTELY' then 'ACUTELYS' else term end ORDER BY SUM(counts) desc
------解决方案--------------------
SELECT top 10 SUM(counts) AS Number, case term when 'ACUTE' then 'ACUTELYS' else term end as Log_Item1 FROM wf_cipin GROUP BY case term when 'ACUTE' then 'ACUTELYS' else term end ORDER BY SUM(counts) desc
------解决方案--------------------
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp GO CREATE TABLE #temp ( word VARCHAR(50), [count] INT, [month] CHAR(7) ) INSERT #temp select 'ACUSAN', '1', '2011-02' union all select 'ACUTE', '1', '2010-11' union all select 'ACUTE', '13', '2010-09' union all select 'ACUTE', '32', '2011-02' union all select 'ACUTE', '5', '2010-12' union all select 'ACUTE', '9', '2011-04' union all select 'ACUTELY', '5', '2010-12' union all select 'ACUTELYS', '1', '2011-02' union all select 'AD', '1', '2010-09' union all select 'AD', '1', '2010-12' union all select 'AD', '29', '2011-02' GO --SQL: DECLARE @word1 VARCHAR(100) SET @word1 = '|ACUTELY|ACUTELYS|' ;WITH cte AS ( SELECT word, [count]=SUM([count]) FROM #temp GROUP BY word ) SELECT word = CASE WHEN CHARINDEX('|'+word+'|', @word1) > 0 THEN @word1 ELSE word END, [count]=SUM([count]) FROM cte GROUP BY CASE WHEN CHARINDEX('|'+word+'|', @word1) > 0 THEN @word1 ELSE word END ORDER BY [count] DESC --RESULT: /* word count ACUTE 60 AD 31 |ACUTELY|ACUTELYS| 6 ACUSAN 1 */
------解决方案--------------------
CREATE TABLE #temp ( word VARCHAR(50), [count] INT, [month] CHAR(7) ) INSERT #temp select 'ACUSAN', '1', '2011-02' union all select 'ACUTE', '1', '2010-11' union all select 'ACUTE', '13', '2010-09' union all select 'ACUTE', '32', '2011-02' union all select 'ACUTE', '5', '2010-12' union all select 'ACUTE', '9', '2011-04' union all select 'ACUTELY', '5', '2010-12' union all select 'ACUTELYS', '1', '2011-02' union all select 'AD', '1', '2010-09' union all select 'AD', '1', '2010-12' union all select 'AD', '29', '2011-02' GO SELECT top 10 SUM(count) AS Number, case word when 'ACUTELY' then 'ACUTELYS' else word end as Log_Item1 FROM #temp GROUP BY case word when 'ACUTELY' then 'ACUTELYS' else word end ORDER BY SUM(count) desc DROP TABLE #temp /******************************* Number Log_Item1 ----------- -------------------------------------------------- 60 ACUTE 31 AD 6 ACUTELYS 1 ACUSAN (4 行受影响)
------解决方案--------------------
SELECT top 10 SUM(counts) AS Number, case term when 'ACUTELY' then 'ACUTELYS' else term end as Log_Item1 FROM wf_cipin GROUP BY case term when 'ACUTELY' then 'ACUTELYS' else term end ORDER BY SUM(counts) desc