select *,
(select count(*) from tb where A.name=name and date between date_add(A.date,interval -3 day) and A.date) as count 3,
(select count(*) from tb where A.name=name and date between date_add(A.date,interval -7 day) and A.date) as count7
from tb A
(select count(*) from tb where A.name=name and date between date_add(A.date,interval -3 day) and A.date) as count 3,
(select count(*) from tb where A.name=name and date between date_add(A.date,interval -7 day) and A.date) as count7
from tb A
解决方案 »
- mysql和mssql数据的实时同步问题...
- mysql 扩展查询遇到的难题
- MySQL Migration Toolkit如何连接Windows集成安全性
- mysql中,这样的语句怎么写? 即如果某表中没有字段ID(主键)的值为10的记录,则插入一条ID值为10的记录,否则什么都不做? 怎么写语句?
- 请教高手 数出本表中同SID同tn的值生成对应的新表 这样可能吗?会有这样的语句吗~~~~~~~~~~~~~~
- [MySQL问题]解决 MySQLdb 操作数据库时的中文问题
- 恭贺PostgreSQL 8.0发布
- 请问:现在成熟的开放源代码数据库有哪些?
- 非常奇怪!MySQL怎么不能安装了?
- 使用mysql C客户端时遇到这样的问题:Character set 'latin1' is not a compiled character
- 求指导,sql优化的问题
- 求找茬。。。
from tb_records a,
(select name,count(*) as c3 from tb_records where `date`>=curdate-interval 3 day group by name ) b,
(select name,count(*) as c7 from tb_records where `date`>=curdate-interval 7 day group by name ) c,
where a.name=b.name and a.name=c.name
只能在from后面使用子查询
大哥,不行,执行不了,貌似是这个思路,我试着改了一下,改不出来还请你出手啊。下面是我之前子查询的,但是需要做成from后面的子查询才行。
select a.*,(select count(1) from tb_records b
where b.num = a.num and b.date <= a.date
and datediff(str_to_date(a.date,'%Y-%m-%d %H:%i:%s.%f'),str_to_date(b.date,'%Y-%m-%d %H:%i:%s.%f')) between 0 and 3 ) as count3,
(select count(1) from tb_records b
where b.num = a.num and b.date <= a.date
and datediff(str_to_date(a.date,'%Y-%m-%d %H:%i:%s.%f'),str_to_date(b.date,'%Y-%m-%d %H:%i:%s.%f')) between 0 and 7 ) as count7
from tb_records a ;