php查询排序最多或最多的单词

时间:2022-02-26 20:25:07

Is there any possible way or query for sorting the most word?

有没有可能的方法或查询来排序最多的词?

for example I have 300 rows and I have this in row 250

例如,我有300行,这个在第250行

Lorem ipsum dolor sit amet, consectetur adipiscing elit

Lorem ipsum dolor坐在amet上,奉献了爱的elit。

and the row 250 got the most/largest amount of word in the column.

第250行得到了列中最多的字。

how can I sort that using mysqli_query($dbcon,"SELECT * FROM wordlist")?

如何使用mysqli_query($dbcon,“从wordlist中选择*”)进行排序?

2 个解决方案

#1


3  

The simplest method is to sort by the length of the column in characters, rather than the number of words:

最简单的方法是按列的长度而不是字数来排序:

select wl.*
from wordlist wl
order by char_length(wl.col) desc;

If you actually want words, then perhaps counting spaces is sufficient:

如果你真的想要单词,那么也许计算空格就足够了:

select wl.*
from wordlist wl
order by (length(wl.col) - length(replace(wl.col, ' ', ''))) desc;

#2


1  

Gordon Linoff's answer is correct and I agree with it, however, I describe an alternative solution. You could store the number of words into the wordlist table in a new column. And you could write an insert and update trigger which would do the calculations shown in Gordon Linoff's answer and store the result into the affected record's corresponding field. In that case number of words would be calculated once per record change, or even on specific column change on the record and could read the stored value as many times you like.

Gordon Linoff的答案是正确的,我同意,但是,我描述了另一种解决方案。您可以将单词数存储到新列的wordlist表中。您可以编写一个插入和更新触发器,它将执行Gordon Linoff的答案中所示的计算,并将结果存储到受影响的记录的相应字段中。在这种情况下,每一次记录的更改,或者甚至在记录上的特定的列更改中,都可以计算一次的单词数量,并且可以像您喜欢的那样多次读取存储的值。

#1


3  

The simplest method is to sort by the length of the column in characters, rather than the number of words:

最简单的方法是按列的长度而不是字数来排序:

select wl.*
from wordlist wl
order by char_length(wl.col) desc;

If you actually want words, then perhaps counting spaces is sufficient:

如果你真的想要单词,那么也许计算空格就足够了:

select wl.*
from wordlist wl
order by (length(wl.col) - length(replace(wl.col, ' ', ''))) desc;

#2


1  

Gordon Linoff's answer is correct and I agree with it, however, I describe an alternative solution. You could store the number of words into the wordlist table in a new column. And you could write an insert and update trigger which would do the calculations shown in Gordon Linoff's answer and store the result into the affected record's corresponding field. In that case number of words would be calculated once per record change, or even on specific column change on the record and could read the stored value as many times you like.

Gordon Linoff的答案是正确的,我同意,但是,我描述了另一种解决方案。您可以将单词数存储到新列的wordlist表中。您可以编写一个插入和更新触发器,它将执行Gordon Linoff的答案中所示的计算,并将结果存储到受影响的记录的相应字段中。在这种情况下,每一次记录的更改,或者甚至在记录上的特定的列更改中,都可以计算一次的单词数量,并且可以像您喜欢的那样多次读取存储的值。