我有一张桌子,我只想用#34; LIMIT 2"选择两行。在那两行我想要应用" CASE"结果之间有MAX和MIN(2行)。
但它正在选择所有行并应用" CASE"在所有行中。
我如何只应用这两个结果?
谢谢。
Table:
user | offer
1 | 10
1 | 10
2 | 20
2 | 20
Query:
SELECT (case when max(offer) = min(offer)
then 'true'
else 'false'
end) as info
FROM user
ORDER BY offer DESC
LIMIT 2
Result that I want to have:
result = true
答案 0 :(得分:1)
您需要在子查询中使用该限制以满足您的要求。
SELECT (case when max(offer) = min(offer)
then 'true'
else 'false'
end) as info
From (Select * FROM user
ORDER BY offer DESC
LIMIT 2)