根据周和年选择数据

时间:2016-06-15 08:24:59

标签: mysql sql mysql-select-db

我有这个sql:

SELECT YEAR(`end`) as week, WEEK(`end`) as year
FROM table
WHERE week=24 AND year=2016 

但我收到错误Unknown column week in where clause。我做错了什么?请帮帮我。 Thx提前

1 个答案:

答案 0 :(得分:2)

你不能在where子句中使用别名,试试这个;)

SELECT WEEK(`end`) as week, YEAR(`end`) as year
FROM table
WHERE WEEK(`end`)=24 AND YEAR(`end`)=2016