【发布时间】:2017-11-28 11:55:42
【问题描述】:
只有当 date_start 和 date_end 的时间差异大于 3 个月时,我才想查询 lat 3 年的用户。我尝试了很多东西,但没有任何效果。这是我到现在为止的声明:
SELECT accounts.account_id, accounts.name, accounts.active_club_id,
accounts.phone, MIN(shifts_accounts.date_start) as 'datestart', MAX(shifts_accounts.date_end) as 'dateend'
FROM `shifts_accounts`
JOIN accounts ON shifts_accounts.account_id = accounts.account_id
JOIN accounts_groups ON accounts.account_id = accounts_groups.account_id
WHERE accounts_groups.group_id = 7
AND DATEDIFF('dateend', 'datestart') > 90
AND accounts.active_club_id != 1
AND shifts_accounts.date_start > '2014-11-28'
AND shifts_accounts.date_start < '2017-11-28' GROUP BY accounts.account_id
【问题讨论】:
-
您不能以这种方式引用别名。但你可以在这种情况下使用 HAVING。
标签: mysql