Advertisement
mikolajmki

wdbd_lab8

Dec 20th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.31 KB | None | 0 0
  1. select firstname, lastname, count (*) from customer
  2. group by firstname, lastname
  3. order by count (*) desc;
  4.  
  5. select c.customerkey, c.lastname, c.firstname, count (*)
  6. from customer c left join orderheader oh on c.customerkey = oh.customerkey
  7. group by c.customerkey, c.lastname, c.firstname
  8. order by c.customerkey
  9.  
  10.  
  11. select firstname, lastname, count (*) from customer
  12. group by firstname, lastname
  13. order by count (*) desc;
  14.  
  15. select c.customerkey, c.lastname, c.firstname,
  16. count (oh.orderkey),
  17. count (distinct oh.paymentmethodkey)
  18. from customer c left join orderheader oh on c.customerkey = oh.customerkey
  19. group by c.customerkey, c.lastname, c.firstname
  20. having count (distinct oh.paymentmethodkey) > 3
  21. order by count(oh.orderkey) desc
  22.  
  23.  
  24. select c.customerkey, c.firstname, c.lastname, count(oh.customerkey)
  25. from orderheader oh
  26. right join customer c on oh.customerkey = c.customerkey
  27. and to_char(oh.orderdate, 'yyyy') = '2019'
  28. group by c.customerkey, c.firstname, c.lastname
  29. order by count(oh.customerkey)
  30.  
  31.  
  32. select oc.channelname "Channel", oc.channelkey "Key", c.countryname "Countryname", count(*) "#Orders" from orderheader oh
  33. left join orderchannel oc on oh.channelkey = oc.channelkey
  34. right join country c on oh.countrykey = c.countrykey
  35. group by oc.channelkey, oc.channelname, c.countryname
  36. order by count(*);
  37.  
  38.  
  39. select c.countryname "Country", oc.channelname "Name", count(oh.orderkey) "#Order" from
  40. country c cross join orderchannel oc
  41. left join orderheader oh
  42. on oh.channelkey = oc.channelkey
  43. group by c.countryname, oc.channelname
  44. order by count(oh.orderkey)
  45.  
  46.  
  47. select sum(od.transactionprice * od.quantity) "Total Orders Value" from
  48. orderdetail od
  49. inner join orderheader oh on od.orderkey = oh.orderkey
  50. group by to_char(oh.orderdate, 'yyyy')
  51.  
  52.  
  53. select to_char(oh.orderdate, 'yyyy'), c.countryname "Name", sum(od.transactionprice * od.quantity) "Total Orders Value" from
  54. orderdetail od
  55. inner join orderheader oh on od.orderkey = oh.orderkey
  56. inner join country c on c.countrykey = oh.countrykey
  57. group by to_char(oh.orderdate, 'yyyy'), rollup(c.countryname)
  58.  
  59.  
  60. select avg((oh.deliverydate - oh.orderdate)), c.countryname, to_char(oh.deliverydate, 'yyyy') "AVG Delivery Time"
  61. from orderheader oh
  62. inner join country c on oh.countrykey = c.countrykey
  63. group by to_char(oh.deliverydate, 'yyyy'), c.countryname
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement