Drop a Query

# October 14, 2023

## How to sort multiple columns in SQL and in different directions?

Problem How to sort multiple columns in SQL and in different directions? Input Let’s create a table named Employees with columns: id, first_name, last_name, and salary. CREATE TABLE Employees ( id INT PRIMARY KEY AUTO_INCREMENT, first_name VARCHAR(100), last_name VARCHAR(100), salary DECIMAL(10, 2) ); — Insert data into the table INSERT INTO Employees (first_name, last_name, salary) …

## How to count the number of work days between two dates?

Problem To count the number of work days between two dates, taking into account weekends (Saturdays and Sundays) and assuming no holidays. Input We will create a table named DateRange with two columns: StartDate and EndDate. Here’s an example input: CREATE TABLE DateRange ( StartDate DATE, EndDate DATE ); INSERT INTO DateRange(StartDate, EndDate) VALUES (‘2023-10-01’, …

## How to compute maximum of multiple columns, aks row wise max?

Problem Given a table with multiple columns, compute the maximum value for each row across the specified columns. Input — Create an example table CREATE TABLE ExampleTable ( ID INT AUTO_INCREMENT PRIMARY KEY, ColumnA INT, ColumnB INT, ColumnC INT ); — Insert data into the table INSERT INTO ExampleTable (ColumnA, ColumnB, ColumnC) VALUES (10, 20, …

## How to use the GROUP BY clause on multiple columns in SQL?

Problem: How to use the GROUP BY clause on multiple columns in SQL? Input: Let’s assume we have a table called Orders with columns OrderID, CustomerID, ProductID, and OrderDate. CREATE TABLE Orders ( OrderID INT PRIMARY KEY, CustomerID INT, ProductID INT, OrderDate DATE ); — Inserting sample data INSERT INTO Orders (OrderID, CustomerID, ProductID, OrderDate) …

Course Preview