我有一个看起来像这样的剧集:
我想从season
episode
的最高季节中获取最高series
然后最高1
(WHERE series = 1)。输出将是:
id | episode | season | series
8 3 1 1
我该怎么做?
答案 0 :(得分:5)
尝试类似的东西:
SELECT * FROM tablename WHERE series = 1 ORDER BY season DESC, episode DESC LIMIT 1;
另一种可能性是" SELECT MAX(...)..."并在WHERE子句中使用它。
答案 1 :(得分:0)
SELECT id, MAX(episode) AS episode, MAX(season) AS season, series
FROM yourTable
WHERE series=1
答案 2 :(得分:0)
SELECT TOP 1 *
FROM testTable
WHERE series= 1 and (season in (select MAX(season) from testTable))
ORDER BY episode DESC
答案 3 :(得分:-1)
您正在寻找MAX()
“最高的项目编号是多少?”