Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. const q15 = `
  2. SELECT lastName, FirstName,
  3. ISNULL((SELECT COUNT(InvoiceId)
  4. FROM Employee e
  5. JOIN Customer c
  6. ON e.EmployeeId = c.SupportRepId
  7. JOIN Invoice i
  8. ON c.CustomerId = i.CustomerId
  9. WHERE e1.employeeId = e.employeeid
  10. GROUP BY e.EmployeeId), 0) as "totalVente",
  11. ISNULL((SELECT i.BillingCountry
  12. FROM Employee e
  13. JOIN Customer c
  14. ON e.EmployeeId = c.SupportRepId
  15. JOIN Invoice i
  16. ON c.CustomerId = i.CustomerId
  17. WHERE e1.employeeId = e.employeeid
  18. GROUP BY e.EmployeeId, i.BillingCountry
  19. HAVING COUNT(i.billingCountry) IN (SELECT max(nbCountry.nb)
  20. FROM
  21. (
  22. SELECT employeeId, COUNT(i.billingCountry) as "nb"
  23. FROM Employee e
  24. JOIN Customer c
  25. ON e.EmployeeId = c.SupportRepId
  26. JOIN Invoice i
  27. ON c.CustomerId = i.CustomerId
  28. GROUP BY e.EmployeeId, i.BillingCountry
  29. ) nbCountry
  30. GROUP BY EmployeeId)), 'N/A') as "pays",
  31. ISNULL((SELECT g.Name
  32. FROM Employee e
  33. JOIN Customer c
  34. ON e.EmployeeId = c.SupportRepId
  35. JOIN Invoice i
  36. ON c.CustomerId = i.CustomerId
  37. JOIN invoiceline il
  38. ON i.invoiceId = il.InvoiceId
  39. JOIN Track t
  40. ON il.TrackId = t.TrackId
  41. JOIN Genre g
  42. ON t.GenreId = g.GenreId
  43. WHERE e1.employeeId = e.employeeid
  44. GROUP BY e.EmployeeId, g.Name
  45. HAVING COUNT(t.genreId) IN (SELECT max(nbGenre.nb)
  46. FROM
  47. (
  48. SELECT employeeId, COUNT(t.genreId) as "nb"
  49. FROM Employee e
  50. JOIN Customer c
  51. ON e.EmployeeId = c.SupportRepId
  52. JOIN Invoice i
  53. ON c.CustomerId = i.CustomerId
  54. JOIN invoiceline il
  55. ON i.invoiceId = il.InvoiceId
  56. JOIN Track t
  57. ON il.TrackId = t.TrackId
  58. GROUP BY e.EmployeeId, t.genreId
  59. ) nbGenre
  60. GROUP BY EmployeeId)), 'N/A') as "mostGenre",
  61. ISNULL((SELECT (COUNT(InvoiceId) / (SELECT MAX(cast(maxVente.nbVentes as decimal(3, 0)))
  62. FROM
  63. (
  64. SELECT COUNT(InvoiceId) as "nbVentes"
  65. FROM Employee e
  66. JOIN Customer c
  67. ON e.EmployeeId = c.SupportRepId
  68. JOIN Invoice i
  69. ON c.CustomerId = i.CustomerId
  70. GROUP BY e.EmployeeId
  71. ) maxVente))*100 as '% ventes par rapport au meilleur vendeurs'
  72. FROM Employee e
  73. JOIN Customer c
  74. ON e.EmployeeId = c.SupportRepId
  75. JOIN Invoice i
  76. ON c.CustomerId = i.CustomerId
  77. WHERE e1.employeeId = e.employeeid
  78. GROUP BY e.EmployeeId
  79. HAVING COUNT(InvoiceId) != (SELECT MAX(maxVente.nbVentes)
  80. FROM
  81. (
  82. SELECT COUNT(InvoiceId) as "nbVentes"
  83. FROM Employee e
  84. JOIN Customer c
  85. ON e.EmployeeId = c.SupportRepId
  86. JOIN Invoice i
  87. ON c.CustomerId = i.CustomerId
  88. GROUP BY e.EmployeeId
  89. ) maxVente)), 0) as "% ventes par rapport au meilleur vendeurs"
  90. FROM Employee e1;
  91. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement