SQLite:选择最大对应值

时间:2021-06-11 15:41:49

I have a table with three columns as follows:

我有一个包含三列的表,如下所示:

id INTEGER    name TEXT    value REAL

How can I select the value at the maximum id?

如何选择最大ID的值?

4 个解决方案

#1


18  

Get the records with the largest IDs first, then stop after the first record:

首先获取ID最大的记录,然后在第一条记录后停止:

SELECT * FROM MyTable ORDER BY id DESC LIMIT 1

#2


7  

Just like the mysql, you can use MAX()

就像mysql一样,你可以使用MAX()

e.g. SELECT MAX(id) AS member_id, name, value FROM YOUR_TABLE_NAME

例如SELECT MAX(id)AS member_id,name,value FROM YOUR_TABLE_NAME

#3


1  

If you want to know the query syntax :

如果您想知道查询语法:

String query = "SELECT MAX(id) AS max_id FROM mytable";

#4


0  

Try this:

尝试这个:

    SELECT value FROM table WHERE id==(SELECT max(id) FROM table));

#1


18  

Get the records with the largest IDs first, then stop after the first record:

首先获取ID最大的记录,然后在第一条记录后停止:

SELECT * FROM MyTable ORDER BY id DESC LIMIT 1

#2


7  

Just like the mysql, you can use MAX()

就像mysql一样,你可以使用MAX()

e.g. SELECT MAX(id) AS member_id, name, value FROM YOUR_TABLE_NAME

例如SELECT MAX(id)AS member_id,name,value FROM YOUR_TABLE_NAME

#3


1  

If you want to know the query syntax :

如果您想知道查询语法:

String query = "SELECT MAX(id) AS max_id FROM mytable";

#4


0  

Try this:

尝试这个:

    SELECT value FROM table WHERE id==(SELECT max(id) FROM table));