我有这个查询按周数显示snowdepth。除了wk,1,2 3等之外,表中没有其他日期(ish)注册。
SELECT
res_id,
wk,
ROUND(templo, 0) AS templo,
ROUND(temphi, 0) AS temphi,
ROUND(snow_valley, 0) AS snow_valley,
ROUND(snow_mountain, 0) AS snow_mountain
FROM
sv_cond_vw_wk
GROUP BY res_id,
wk
HAVING (res_id = 6)
AND (wk = 51
OR wk = 52
OR wk = 52
OR wk < 13)
在第12周之后输出第51周和第52周但我希望在第1周之前得到它: 51,52,1,2,3,4
答案 0 :(得分:1)
您可以在FIELD(wk,52,51) DESC
子句中使用ORDER BY
,以便wk =&gt;首先出现51然后wk =&gt; 52然后休息
SELECT
res_id,
wk,
ROUND(templo, 0) AS templo,
ROUND(temphi, 0) AS temphi,
ROUND(snow_valley, 0) AS snow_valley,
ROUND(snow_mountain, 0) AS snow_mountain
FROM
sv_cond_vw_wk
GROUP BY res_id,
wk
HAVING (res_id = 6)
AND (wk = 51
OR wk = 52
OR wk < 13)
ORDER BY FIELD(wk,52,51) DESC , wk