简体   繁体   中英

mysql select rows with top max value

i have a table in mysql with columns: id , view , agree . i have upload my table 's image below:

在此处输入图片说明

i want to select 8 rows that greater than others in view column. my condition is agree = 1 .

can you tell me how can i do it by query or .

Select * from table_name WHERE agree = 1 ORDER BY view desc LIMIT 8 

Try this:

SELECT * from table
WHERE agree = 1 
ORDER BY view DESC
LIMIT 8 

use limit and order by

Select * from mytable 
where aggree=1 
ORDER BY view DESC 
LIMIT 8

You can do this:

SELECT *
FROM yourTableName
WHERE agree = 1
ORDER BY view DESC
LIMIT 8

您必须使用ORDER BY子句。

SELECT * FROM <TABLE_NAME> WHERE AGREE = 1 ORDER BY VIEW DESC LIMIT 8

Use ORDER BY for DESC or ASC sorting.

and For selection of 8 rows use Limit Data Selections From a MySQL Database

Select * from table_name WHERE agree = 1 ORDER BY view desc LIMIT 8 

If you want to take the top 8 'view' values from the table the MySql query for that is:

SELECT  * FROM tablename  WHERE agree=1 ORDER BY view DESC LIMIT 8;

Note: Replace tablename with the actual name of your table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM