Answer: Using CROSS JOIN
Explore how to use CROSS JOIN in SQL to generate all possible row combinations between tables and solve complex data retrieval tasks. Understand key concepts such as joins, aggregate functions, aliases, and grouping while learning alternative query methods to count sales per employee by product category.
Solution
The solution is given below:
Code explanation
The explanation of the solution code is given below:
Lines 2–4: The
SELECTstatement selects the columnsEName,CategoryName, and count of sales made using the aggregate function with theSalesIDcolumn. We useASto set an alias for the columns and tables.Line 5: The data is retrieved from the
Employeestable.Line 6: The
CROSS JOINis performed betweenEmployeesandProductCategories.Line 7: The
LEFT JOINis performed withSales,Employees, andProductCategorieson the columnsEIDandCategoryID. ...