sql server - Multiple Rows to Single Row -
how can retrieve result if given multiple row data
the result base on performed column. condition start tserv_id ‘discharge’ , end ‘onpower’.
the conditions:
- discharge onpower (1 row)
- any performed between last 1) onpower-------------- onpower (1 row)
- any performed between last 2) onpower-------------- onpower (1 row)
- any performed between last 3) onpower ---------------onpowewr (1 row)
code:
select min(case tserv_id when 'discharge' performed end) tserv_discharge, min(case tserv_id when 'onpower' performed end) tserv_onpower --how retrieve data performed between disharge & first onpower? ods_reefer eq_nbr = 'a1234'; select min(case tserv_id when 'onpower' performed end) tserv_onpower, max(case tserv_id when 'onpower' performed end) tserv_onpower --how exclude performed first onpower , how read performed between second onpower? ods_reefer eq_nbr = 'a1234';
use aggregation:
select min(case tserv_id when 'discharge' performed end) tserv_discharge, min(case tserv_id when 'onpower' performed end) tserv_onpower, min(case tserv_id when 'yard2truck' performed end) tserv_yard2truck, min(case tserv_id when 'full out' performed end) tserv_fullout, min(case tserv_id when 'full in' performed end) tserv_fullin ods_reefer eq_nbr = 'egsu5014174';
Comments
Post a Comment