开发者

Order Mysql Value Listing by Amount

开发者 https://www.devze.com 2023-02-13 02:01 出处:网络
I have this database with a table and a row called \'rank\'. In that database table there are 2 teams. Each Get ranked every day.

I have this database with a table and a row called 'rank'.

In that database table there are 2 teams. Each Get ranked every day.

Ex.

Day 1.

Team F - rank =1 Team R - rank =2

Day 2.

Team R - rank =1 Team F - rank =2


So i want the teams to appear on top because of their higher rank

Right now I got this: (appear as entered)-w开发者_JAVA技巧hile($person = mysql_fetch_array($result)) {

So what do I put in that code in order to make it be the highest value of a column.

any ideas?


Could you be more specific about your table layout? Maybe provide the CREATE TABLE SQL that was used to create it?

To order results by value, you can end a sql query with ORDER BY column_name DESC in order to get the results returned in MAX -> MIN order of that column. You can replace DESC with ASC to get it to go in MIN -> MAX order. If you don't put DESC or ASC it defaults to one of them, but I forget which.

If you want to sort on more than one column, put them in the ORDER BY as comma separated. So ORDER BY column1, column2 DESC will produce a listing that is ordered from the greatest value of column1 to the least value, and anytime the values of column1 are identical between rows, it will orders those by column2.

If I read your question correctly, and you in fact have a "row" named rank, then something is wrong with your table structure, as you can't really name "rows" (and SQL generally refers to rows as records, anyway).


Add an order clause at the end of your query.

Something like:

ORDER BY day DESC, RANK asc
0

精彩评论

暂无评论...
验证码 换一张
取 消