[英]Count days in date range?
I have a query like this:我有一个这样的查询:
SELECT COUNT(*) AS amount
FROM daily_individual_tracking
WHERE sales = 'YES'
AND daily_individual_tracking_date BETWEEN '2010-01-01' AND '2010-03-31'
I am selected from a date range.我是从一个日期范围中挑选出来的。 Is there a way to also get the total days in the date range?有没有办法获得日期范围内的总天数?
Not really clear if you are looking for不是很清楚你是否正在寻找
DATEDIFF('2010-03-31', '2010-01-01')
or或者
COUNT(DISTINCT daily_individual_racking_date)
You can use the MySQL datediff
function:您可以使用 MySQL datediff
函数:
SELECT DATEDIFF('2010-01-01','2010-01-31') AS DiffDays
It should return a floating point, where 1.0
represents a single day.它应该返回一个浮点数,其中1.0
代表一天。
And for MS SQL use ,对于 MS SQL 使用,
SELECT DATEDIFF( day ,'2010-01-01','2010-01-31') AS DiffDays
What exactly are you trying to count?你到底想数什么? The total number of distinct values of daily_individual_tracking_date? Daily_individual_tracking_date 的不同值的总数? Do you need it in the same query as the count(*) query?您是否需要在与 count(*) 查询相同的查询中使用它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.