SQL script with column '-1'

1

I have this SQL script:

create view transactview as (
 select SUM(quantity) as venta,tag,shift_id,pump,nozzle from transactions 
 where tag in (100,200,300,400) group by tag,shift_id,pump,nozzle
 union select SUM(quantity) as venta,'-1',shift_id,pump,nozzle from transactions
 where tag not in (100,200,300,400) group by shift_id,pump,nozzle )

And I do not understand the function of the column '-1' in the second "Select" or because it is there.

Thanks

    
asked by Camilo Medina 12.08.2016 в 16:13
source

1 answer

2

The -1 value is a default value assigned as the second column of the second SELECT.

This is your query a little more organized :

create view transactview as
(
   select SUM(quantity) as venta, tag, shift_id, pump, nozzle 
   from transactions 
   where tag in (100,200,300,400)
   group by tag,shift_id,pump,nozzle
   union 
   select SUM(quantity) as venta, '-1', shift_id, pump, nozzle 
   from transactions
   where tag not in (100,200,300,400)
   group by shift_id,pump,nozzle
)

In your case, it would be the value assigned to the column tag .

    
answered by 12.08.2016 / 16:25
source