光标检查单词 [英] Cursor to check words
问题描述
我在sql server表中有数百万字的Engtitle字段。
我想检查表中每个单词重复多少次以下条件:
I have Engtitle field in sql server table with millions of words.
I want to check how many times each word of table repeats within the table with following condition:
select distinct engtitle from table
where a1 = 'EHD'
我将通过上述查询获得200万条记录。我想在同一张表中检查上述查询中的每个单词..条件如下:
假设@variable是我从上面查询得到的一个单词
I will get 2million records with above query.and i want to check each word from above query in within same table..with this condition:
Suppose @variable is a one word i get from above query
select COUNT(*) from table
where engtitle like '%@variable %'
我想在表格中插入每个单词的计数。表2( engtitle,count)
对于上述条件,我尝试了以下光标:
and I want to insert each word with their counts in a table..table2(engtitle,count)
For above condition I tried following cursor:
declare @Engword varchar(max)
DECLARE word_cursor CURSOR FOR
select distinct engtitle from table
where a1 = 'EHD'
ORDER BY Engtitle;
OPEN Word_cursor;
FETCH NEXT FROM Word_cursor
INTO @Engword;
Print @Engword + 'f'
WHILE (select COUNT(*) from table where engtitle like '%@Engword %') > 0 and @@FETCH_STATUS = 0
BEGIN
Print @Engword + 's'
Insert into Table1(Engtitle,[count])
Values(@Engword,(select COUNT(*) from table
where engtitle like '%@Engword %'))
IF (select COUNT(*) from table
where engtitle like '%@Engword %' ) < 0
Begin
Insert into Table1(Engtitle,[count])
Values(@Engword,(select COUNT(*) from table
where engtitle like '%@Engword %'))
END
FETCH NEXT FROM Word_cursor
INTO @Engword;
END
CLOSE Word_cursor;
DEALLOCATE Word_cursor;
GO
推荐答案
为什么不:
SELECT engtitle,COUNT(*)FROM table GROUP BY engtitle
这篇关于光标检查单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!