现在有如下3张表
a(总量)
-----------------------
1 2008-08-12 10:42:09
2 2008-11-27 10:16:09
3 2008-11-27 12:42:09
4 2008-11-27 10:44:09
5 2008-12-05 10:42:09
-----------------------b(成功)
-----------------------
1 2008-11-27 10:16:09
2 2008-11-27 10:42:09
3 2008-08-12 10:42:09
-----------------------c(失败)
-----------------------
1 2008-11-27 10:44:09
2 2008-12-05 10:42:09
-----------------------现在我想用一条SQL语句就查询出11月份中每天 a的总量,b的总量,c的总量,该怎么查询啊?
分开了我会做如下:
select date_format(create_date,"%Y-%m-%d") as time,count(*) as total
from t_cr_ringlib_diy where date_format(create_date,"%Y-%m")='2008-11' group by day(create_date)
a(总量)
-----------------------
1 2008-08-12 10:42:09
2 2008-11-27 10:16:09
3 2008-11-27 12:42:09
4 2008-11-27 10:44:09
5 2008-12-05 10:42:09
-----------------------b(成功)
-----------------------
1 2008-11-27 10:16:09
2 2008-11-27 10:42:09
3 2008-08-12 10:42:09
-----------------------c(失败)
-----------------------
1 2008-11-27 10:44:09
2 2008-12-05 10:42:09
-----------------------现在我想用一条SQL语句就查询出11月份中每天 a的总量,b的总量,c的总量,该怎么查询啊?
分开了我会做如下:
select date_format(create_date,"%Y-%m-%d") as time,count(*) as total
from t_cr_ringlib_diy where date_format(create_date,"%Y-%m")='2008-11' group by day(create_date)
解决方案 »
- -- 一个奇怪的My SQL游标循环问题 --
- 怎么把一个字段拆分为三个字段,然后对表中的另外三个字段赋值,进行修改?
- excel 表格如何导入到myqsql 数据库中 请求源码事例
- 求一条SQL语句
- 插入语句问题
- 100分:mysql关于年龄段统计语句请教!!
- 如何删除这样的数据?
- Mysql 中 Column 'user' not found.的奇怪问题
- (100分)在mysql中,select * from table1 LEFT JOIN table2 ON table1.id=table2.id,哪一个是左表,哪一个是右表,怎样使用 left joi
- █████████请教MySQL高手:一个表中建立两个CONSTRAINT█████████
- MySql如果用于商业用途是要收费的吗?
- 关于drop 索引的问题~~~?
select date_format(create_date,"%Y-%m") as aa,count(*) from a
where date_format(create_date,"%Y-%m")='2008-11
group by date_format(create_date,"%Y-%m")) a1left join
(
select date_format(create_date,"%Y-%m") as bb,count(*) from b
where date_format(create_date,"%Y-%m")='2008-11
group by date_format(create_date,"%Y-%m")) a2
on a1.aa=a2.bbleft join
(
select date_format(create_date,"%Y-%m") as cc,count(*) from c
where date_format(create_date,"%Y-%m")='2008-11
group by date_format(create_date,"%Y-%m")) a3
on a1.aa=a3.cc
select * from (
select date_format(create_date,"%Y-%m-%d") as time,count(*) as total from t_cr_ringlib_diy
where date_format(create_date,"%Y-%m")='2008-11'
group by day(create_date)) t 比如第一句,select * from()t 这样写什么意思不太明白
还请WWWWA指教一下啊!
where date_format(create_date,"%Y-%m")='2008-11'
group by day(create_date)以上是一个查询结果啊,为什么放在from的后面呢? from的后面不是要放查询表的吗?
select * from (
select date_format(create_date,"%Y-%m-%d") as time,count(*) as total from t_cr_ringlib_diy
where date_format(create_date,"%Y-%m")='2008-11'
group by day(create_date)) t
这句来讲,不用SELECT * FROM () t,但你的查询是三张表分组再连接,
就要加SELECT * FROM ()
非常感谢WWWWA!