我有一个数据库,我想输出POSITION为49且ID最高的行的VAL。我有这段代码,但是我不确定从这里去哪里。
SELECT ID, POSITION,
CASE WHEN POSITION = 49 THEN VAL END
FROM Log
答案 0 :(得分:2)
最简单的解决方案是
SQL-SERVER
SELECT top 1 val
FROM Log
where position = 49
order by id desc
MySQL
SELECT val
FROM Log
where position = 49
order by id desc
limit 1