a表
aa, bb13 2010-8-1
12 2010-8-2
11 2010-8-3
10 2010-8-4如果我输入的日期是 2010-8-4
那么得到的结果就是13+12+11+1如果我输入的日期是 2010-8-3
那么得到的结果就是13+12+11规律是,输入一个日期,然后从本月的1号开始到输入的日期,aa字段相加
aa, bb13 2010-8-1
12 2010-8-2
11 2010-8-3
10 2010-8-4如果我输入的日期是 2010-8-4
那么得到的结果就是13+12+11+1如果我输入的日期是 2010-8-3
那么得到的结果就是13+12+11规律是,输入一个日期,然后从本月的1号开始到输入的日期,aa字段相加
解决方案 »
- MySQL innodb 出错 lost connection
- mysql 权限中的 % localhost 关系
- PostgreSQL 逃逸问题
- 关于mysql查询的奇怪问题~~
- postgresql时间触发器
- 请教高手一个MYSQL问题,急!!
- 又是一个MYSQL编码问题
- mysql中如何查出符合另一个表中条件的数据?急
- 急问,windows下mysql如何更改字符集?
- 开源的MySQL管理小工具myadmin tools 发布啦
- 怎么改 memeo 类型的数据 update nvc_safecfg set value = 1 where key='safemode';
- 颜色标出的部分,有什么办法可以整合到一起
select sum(aa) from a where bb>='2010-8-1' and bb<='2010-8-4'
mysql> create table a(aa int,bb date);
Query OK, 0 rows affected (0.23 sec)mysql> insert into a values(13,'2010-08-01'),(12,'2010-08-02'),(11,'2010-08-03'),(10,'2010-08-04')
-> ;
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0mysql> select * from a;
+------+------------+
| aa | bb |
+------+------------+
| 13 | 2010-08-01 |
| 12 | 2010-08-02 |
| 11 | 2010-08-03 |
| 10 | 2010-08-04 |
+------+------------+
4 rows in set (0.00 sec)mysql> select sum(aa) from a where year(bb)=year('2010-08-04') and month(bb)=month('2010-08-04') and day(bb)<=day('2010-08-04');
+---------+
| sum(aa) |
+---------+
| 46 |
+---------+
1 row in set (0.02 sec)mysql> select sum(aa) from a where year(bb)=year('2010-08-03') and month(bb)=month('2010-08-03') and day(bb)<=day('2010-08-03');
+---------+
| sum(aa) |
+---------+
| 36 |
+---------+
1 row in set (0.01 sec)
12 2010-8-2
11 2010-8-3
10 2010-8-4===>select sum(aa)
from A
where bb between concat(date_format(输入的日期,'%Y-%m'),'-01') and 输入日期
from a表
where bb between @输入一个日期-interval DAYOFMONTH(@输入一个日期)-1 day and @输入一个日期