Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. CREATE TABLE sales (
  2. id int,
  3. currency VARCHAR(5),
  4. price int
  5. shop_id int
  6. );
  7.  
  8. SELECT shop_id, (CASE WHEN currency= "GBP" THEN SUM(price) ELSE 0 END) AS POUND , (CASE WHEN currency= "USD" THEN SUM(price) ELSE 0 END) AS USDOLLAR GROUP BY shop_id, currency
  9.  
  10. _________________________________________
  11. shop_id | POUND | USDOLLAR |
  12. -----------------------------------------
  13. 1 | 400 | 300 |
  14. -----------------------------------------
  15. 2 | 250 | 100 |
  16. -----------------------------------------
  17. 3 | 400 | 100 |
  18. -----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement