求助,sql语句不会写
select distinct a.station_id,b.type_name,c.data_time
from t_data_item a,t_data_type b,t_data c
where a.station_id=334
and a.type_id=b.type_id
and a.item_id=c.item_id
and b.type_name like '%报警%'
and c.data_time>=to_date('2009-02-26 00:00:00','yyyy-mm-dd hh24:mi:ss')
and c.data_time<to_date('2009-02-27 00:00:00','yyyy-mm-dd hh24:mi:ss')
group by a.station_id,b.type_name,c.data_time
这个语句查询结果如下:
STATION_ID TYPE_NAME DATA_TIME
1334 倒流报警2009-2-26 6:03:00
2334 倒流报警2009-2-26 3:26:00
3334 倒流报警2009-2-26 6:38:00
4 334 低电压报警 2009-2-26 6:38:00
5 334 低电压报警 2009-2-26 3:26:00
我现在希望查询出来的结果是这样:
1334 倒流报警 3
2 334 低电压报警 2
即,统计一下同种类型报警出现的次数,该怎么改这个sql语句?
[解决办法]
1、假设上述代码存为VIEW1
SELECT TYPE_NAME,COUNT(*) FROM VIEW1 GROUP BY TYPE_NAME
[解决办法]
路过看看
[解决办法]
select a.station_id,b.type_name,count(*)from t_data_item a,t_data_type b,t_data c where a.station_id=334 and a.type_id=b.type_id and a.item_id=c.item_id and b.type_name like '%报警%' and c.data_time>=to_date('2009-02-26 00:00:00','yyyy-mm-dd hh24:mi:ss') and c.data_time <to_date('2009-02-27 00:00:00','yyyy-mm-dd hh24:mi:ss') group by a.station_id,b.type_name