首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果datediff大于

如果datediff大于
EN

Stack Overflow用户
提问于 2017-11-28 11:55:42
回答 2查看 807关注 0票数 0

只有当date_start和date_end的时间差大于3个月时,我才会从lat询问用户。我试过很多东西,但都没有用。这是我迄今为止所做的声明:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-28 12:09:05

下面是一个有效查询的示例。我不认为有足够的信息来说明你是否想要.

代码语言:javascript
复制
SELECT a.account_id
     , a.name
     , a.active_club_id
     , a.phone
     , MIN(sa.date_start) datestart
     , MAX(sa.date_end) dateend 
  FROM shifts_accounts sa
  JOIN accounts a
    ON a.account_id = sa.account_id 
  JOIN accounts_groups ag
    ON ag.account_id = a.account_id 
 WHERE ag.group_id = 7 
   AND a.active_club_id != 1 
   AND sa.date_start BETWEEN '2014-11-28' AND '2017-11-28' 
 GROUP 
    BY a.account_id
HAVING DATEDIFF(dateend, datestart) > 90;

有关进一步帮助,请参见:Why should I provide an MCVE for what seems to me to be a very simple SQL query?

票数 0
EN

Stack Overflow用户

发布于 2017-11-28 11:59:05

试试这个,

代码语言:javascript
复制
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 < DATE_SUB(NOW(),INTERVAL 3 YEAR) GROUP BY accounts.account_id
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47530997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档