我有一个带有单词的varchar列。我想动态创建@variables并使用列中的值命名每个变量以保持每个单词的计数。
//Define all variables in PHP dynamically
@word1:=0, @word2:=0;
//Select and count how many times each word exists
SELECT (@column_value:=@column_value+1) AS words FROM Data ORDER BY words
上面的“@column_value”应为“@ word1”..“@ word2”等。
感谢您的帮助。
答案 0 :(得分:0)
为什么不用正常的计数SQL功能计算单词,如:
SELECT word, COUNT(word) as `count`
FROM Data
GROUP BY word
ORDER BY word ASC