我有一个包含两列的表,如图所示
表的列名是(MAXDATE,AMOUNT)。
如果你看到我们有
first date range (from current date to 20-jan-2010)
second date range from 20-jan-2010 to 30-jan-2010
3rd range is from 20-jan-2010 to 31-jan-2010.
执行页面用户时输入开始和结束日期。
例如,如果用户输入
start date: 18-jan-2010
end date: 23-jan-2010
然后他在第一个选项中有2个日期,在第二个选项中有3个日期。
我想在sql中计算什么
1. how many days in first range (if any this depends on supplied dates from user)
2. how many days in 2nd range (if any this depends on supplied dates from user)
3. how many days in 3rd range (if any this depends on supplied dates from user)
由于
答案 0 :(得分:1)
答案 1 :(得分:0)
你可以在MySQL中完成所有这些:
SELECT DATEDIFF(NOW(), max_date) as days;
SELECT DATEDIFF(date2, date1) FROM
(SELECT max_date as date1 FROM table1 LIMIT 1) as s1
JOIN
(SELECT max_date as date2 FROM table1 LIMIT 1 OFFSET 1) as s2;
//etc.