ow do I make (swap) EMP_NUM from line 2 to 1? see attached SELECT emp.EMP_NUM, EMP_FNAME, EMP_LNAME, EMP_EMAIL, TOTAL FROM LGEMPLOYEE AS emp INNER JOIN (SELECT employee_id, sum(line_qty) AS total FROM LGINVOICE AS i INNER JOIN LGLINE as l ON i.inv_num = l.inv_num INNER JOIN LGPRODUCT AS p ON l.prod_sku = p.prod_sku INNER JOIN LGBRAND AS b ON b.brand_id = p.brand_id WHERE brand_name = 'Binder Prime' AND inv_date BETWEEN '2017-11-01' AND '2017-12-05' GROUP BY employee_id) AS sub ON emp.emp_num = sub.employee_id WHERE total = (SELECT max(total) FROM (SELECT employee_id, sum(line_qty) AS total FROM LGINVOICE AS i INNER JOIN LGLINE as l ON i.inv_num = l.inv_num INNER JOIN LGPRODUCT AS p ON l.prod_sku = p.prod_sku INNER JOIN LGBRAND AS b ON b.brand_id = p.brand_id WHERE brand_name = 'Binder Prime' AND inv_date BETWEEN '2017-11-01' AND '2017-12-05'
How do I make (swap) EMP_NUM from line 2 to 1? see attached
SELECT emp.EMP_NUM, EMP_FNAME, EMP_LNAME, EMP_EMAIL, TOTAL
FROM LGEMPLOYEE AS emp INNER JOIN
(SELECT employee_id, sum(line_qty) AS total
FROM LGINVOICE AS i INNER JOIN LGLINE as l ON i.inv_num = l.inv_num
INNER JOIN LGPRODUCT AS p ON l.prod_sku = p.prod_sku
INNER JOIN LGBRAND AS b ON b.brand_id = p.brand_id
WHERE brand_name = 'Binder Prime'
AND inv_date BETWEEN '2017-11-01' AND '2017-12-05'
GROUP BY employee_id) AS sub
ON emp.emp_num = sub.employee_id
WHERE total = (SELECT max(total)
FROM (SELECT employee_id, sum(line_qty) AS total
FROM LGINVOICE AS i INNER JOIN LGLINE as l ON i.inv_num = l.inv_num
INNER JOIN LGPRODUCT AS p ON l.prod_sku = p.prod_sku
INNER JOIN LGBRAND AS b ON b.brand_id = p.brand_id
WHERE brand_name = 'Binder Prime'
AND inv_date BETWEEN '2017-11-01' AND '2017-12-05'
GROUP BY employee_id) as sub1);
Trending now
This is a popular solution!
Step by step
Solved in 2 steps