Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const q15 = `
- SELECT lastName, FirstName,
- ISNULL((SELECT COUNT(InvoiceId)
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- WHERE e1.employeeId = e.employeeid
- GROUP BY e.EmployeeId), 0) as "totalVente",
- ISNULL((SELECT i.BillingCountry
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- WHERE e1.employeeId = e.employeeid
- GROUP BY e.EmployeeId, i.BillingCountry
- HAVING COUNT(i.billingCountry) IN (SELECT max(nbCountry.nb)
- FROM
- (
- SELECT employeeId, COUNT(i.billingCountry) as "nb"
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- GROUP BY e.EmployeeId, i.BillingCountry
- ) nbCountry
- GROUP BY EmployeeId)), 'N/A') as "pays",
- ISNULL((SELECT g.Name
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- JOIN invoiceline il
- ON i.invoiceId = il.InvoiceId
- JOIN Track t
- ON il.TrackId = t.TrackId
- JOIN Genre g
- ON t.GenreId = g.GenreId
- WHERE e1.employeeId = e.employeeid
- GROUP BY e.EmployeeId, g.Name
- HAVING COUNT(t.genreId) IN (SELECT max(nbGenre.nb)
- FROM
- (
- SELECT employeeId, COUNT(t.genreId) as "nb"
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- JOIN invoiceline il
- ON i.invoiceId = il.InvoiceId
- JOIN Track t
- ON il.TrackId = t.TrackId
- GROUP BY e.EmployeeId, t.genreId
- ) nbGenre
- GROUP BY EmployeeId)), 'N/A') as "mostGenre",
- ISNULL((SELECT (COUNT(InvoiceId) / (SELECT MAX(cast(maxVente.nbVentes as decimal(3, 0)))
- FROM
- (
- SELECT COUNT(InvoiceId) as "nbVentes"
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- GROUP BY e.EmployeeId
- ) maxVente))*100 as '% ventes par rapport au meilleur vendeurs'
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- WHERE e1.employeeId = e.employeeid
- GROUP BY e.EmployeeId
- HAVING COUNT(InvoiceId) != (SELECT MAX(maxVente.nbVentes)
- FROM
- (
- SELECT COUNT(InvoiceId) as "nbVentes"
- FROM Employee e
- JOIN Customer c
- ON e.EmployeeId = c.SupportRepId
- JOIN Invoice i
- ON c.CustomerId = i.CustomerId
- GROUP BY e.EmployeeId
- ) maxVente)), 0) as "% ventes par rapport au meilleur vendeurs"
- FROM Employee e1;
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement