sql server - Multiple Rows to Single Row -


how can retrieve result if given multiple row data

show multiple row data

the result base on performed column. condition start tserv_id ‘discharge’ , end ‘onpower’.

the conditions:

  1. discharge onpower (1 row)
  2. any performed between last 1) onpower-------------- onpower (1 row)
  3. any performed between last 2) onpower-------------- onpower (1 row)
  4. any performed between last 3) onpower ---------------onpowewr (1 row)

output

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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -