【发布时间】:2021-11-09 12:58:47
【问题描述】:
我的第一个查询是
select GEAR,count(GEAR)
from new_failure
where STN_CODE = "BVH" group by(Gear);
它的结果是
图片不可见时的结果
# GEAR Total
SIGNAL 8
POINT 16
HASSDAC 5
,SIGNAL 1
SSDAC 1
TRACK CIRCUIT 9
UFSBI 2
DC 1
第二次查询
select GEAR,count(GEAR)
from new_failure
where STN_CODE = "BVH"
and MONTH(fail_time) = 4
group by(Gear);
结果
# GEAR April
SIGNAL 3
POINT 4
HASSDAC 1
,SIGNAL 1
SSDAC 1
我希望结果如下图所示
【问题讨论】:
-
select t1.Gear, t1.[This],COALESCE(t2.[April],0) AS [ April] from (select GEAR,count(GEAR) as "This" from new_failure where STN_CODE = "BVH" group by(Gear)) t1 LEFT JOIN (select GEAR,count(GEAR) as "April" from new_failure 其中STN_CODE = "BVH" and MONTH(fail_time) = 4 group by(Gear)) t2 on (t1 .Gear = t2.Gear);我的查询看起来像这样,但在 t1 出现错误。[this] "[" is not valid
标签: mysql