Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.04 KB | None | 0 0
  1. /**
  2.  
  3. Given the following table
  4.  
  5. customer                              product
  6. +---------------+---------+           +---------------+---------+
  7. | id            | int     |-----+  +--| id            | int     |
  8. | age           | int     |     |  |  | price         | double  |
  9. | gender        | char    |     |  |  +---------------+---------+
  10. +---------------+---------+     |  |  
  11.                                 |  |  sale
  12.                                 |  |  +---------------+---------+
  13.                                 |  |  | id            | int     |
  14.                                 |  +->| product_id    | int     |
  15.                                 +---->| customer_id   | int     |
  16.                                       +---------------+---------+
  17. */
  18.  
  19.  
  20.  
  21. /**
  22.  * 1. Get the total revenue for all males in the customer database.
  23.  *
  24.  *
  25. */
  26.  
  27. # select * from customer limit 10;
  28.  
  29.  
  30. select sum(p.price)
  31. from customers c left outer join sales s
  32. on c.id = s.customer_id
  33. left outer join products p
  34. on s.product_id = p.id
  35. where c.gender = 'm';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement