SQL one select with different where clauses -


I have to make a selection with individual where segment (with different product code). The result I need is below

I have a table:

  APID | Date | Code | Volume | Price | Amount 222 | 2014-10-11 | 555 | 1 | 2,22. 2,222.22 2014-10-11 | 555 | 1 | 2,22. 2,222.22 2014-10-11 | 333 | 1 | 3,33 3,33 222 | 2014-10-12 | 555 | 1 | 2,22. 2,22  

My query:

  select 'date' as date (date), SUM ( Quantity * Price 'as' Yoga ',' APID = 222 APID = 222 and data '2014-10-11' and '2014-10-13' and code from the table as the amount (quantity) Like the '555' cast by group (as the date of Quitogalva).  

I get a result like this:

 < Code> data | Yoga | Volume 2014-10-11 | 4.44 | 2 2014-10-12 | 2.22 | 1  

I need to display the result in a table:

  data | Amount 555 | Quantity 555 | Amount 333 Quantity 333 | 2014-10-11 | 4.44 | 2 | 3.33 | 1 | 2014-10-12 | 2.22 | 1 | 0 | 0 | Tried  

:

  (select 1), (selection 2)) ------------ ----- ----------- SELECT 1 Select Union 2  

You can do this by using conditional aggregation: Select

  as the data type (date), SUM (case when code = '555' then quantity * value other 0) AS Sum555, SUM (case when code = '555' then quantity other 0 end) AS Qty555, SUM (in case when code = '333' then quantity * value second zero) AS Sum333, SUM (if code = ' 333 'then the other quantity ) Table T APID = 222 from ADF 833 and '2014-10-11' and '2014-10-13' between the data and the code ('555', '333') by group cast (KvitoGalva.Data as DATE );  

Note: Use single quotes only for string and date constants You do not need quote for column nicknames and if you have done so, to avoid names in your database Will be a better character.


Comments