gpt4 book ai didi

php - 如何使用 Between 条件从表中选择值

转载 作者:行者123 更新时间:2023-11-29 14:26:22 25 4
gpt4 key购买 nike

我想要一个条件来获取日期之间的值。

我有一个表名 user 和一个列 date,我想使用日期条件从数据库中获取值。

select sum(visitor) AS V FROM user  WHERE date  < '21-05-2012' AND dDateTime > '11-05-2012' 
select sum(visitor) AS c FROM user WHERE date < '21-06-2012' AND dDateTime > '11-06-2012'
select sum(visitor) AS s FROM user WHERE date < '21-07-2012' AND dDateTime > '11-07-2012'
select sum(visitor) AS g FROM user WHERE date < '21-08-2012' AND dDateTime > '11-08-2012'

我想在一个sql语句中执行这四个查询

最佳答案

也许是这样的:

select 
sum(CASE WHEN date < '21-05-2012' AND dDateTime > '11-05-2012' THEN visitor ELSE 0 END) AS V,
sum(CASE WHEN date < '21-06-2012' AND dDateTime > '11-06-2012' THEN visitor ELSE 0 END) AS c,
sum(CASE WHEN date < '21-07-2012' AND dDateTime > '11-07-2012' THEN visitor ELSE 0 END) AS s,
sum(CASE WHEN date < '21-08-2012' AND dDateTime > '11-08-2012' THEN visitor ELSE 0 END) AS g
FROM
user

关于php - 如何使用 Between 条件从表中选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10893137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com