This repository contains a collection of SQL code snippets for various purposes. Feel free to browse through the snippets and use them in your projects.
Each SQL file contains a specific code snippet. You can use these snippets directly in your database management system or incorporate them into your projects.
- BasicSelect.sql: Retrieves all information about suppliers from the Northwind database.
- PartialSelect.sql: Retrieves partial information about suppliers from the Northwind database.
- OrderBy.sql: Retrieves information about suppliers sorted by city from the Northwind database.
- Distinct.sql: Retrieves unique cities where supplier locations are found from the Northwind database.
- WhereIn.sql: Retrieves formatted company names from suppliers located in London and Osaka from the Northwind database.
- Like.sql: Retrieves companies whose names start with the letter B from the Northwind database.
- Length.sql: Retrieves companies whose names are longer than 10 characters from the Northwind database.
- Like%.sql: Retrieves addresses from suppliers where the address starts with '22' from the Northwind database.
- WhereGreaterThan.sql: Retrieves product names and the quantity needed to purchase in order to exceed the reorder level from the Northwind database.
- ReorderLevel.sql: Retrieves product names, supplier addresses, and the quantity of products needed to purchase in order to exceed the reorder level by 100 units from the Northwind database.
- DiscontinuedProducts.sql: Retrieves the names of products that have been discontinued from the Northwind database.
- BirthdateFilter.sql: Retrieves employees born before January 1, 1980, from the Northwind database.
- DateComparison.sql: Checks if the birthdate of employees is greater than their hire date in the Northwind database.
- AverageSalary.sql: Calculates the average salary of employees in the company, rounding the result to two decimal places.
- SalaryStatistics.sql: Displays the minimum, maximum, and average salary of employees in the company.
- SalesRepresentativeAverageSalary.sql: Shows the average salary of Sales Representatives in both dollar and local currency formats.
- EmployeeCityCount.sql: Shows the number of employees per city they reside in from the Northwind database.
- EmployeeCityCountFilter.sql: Filters cities with more than 2 employees from the Northwind database.
- BestPay.sql: Retrieves the three highest-paid employees from the company.
- ProductsFromExoticLiquids.sql: Retrieves products supplied by Exotic Liquids.
- ProductsFromLekaTradingWithStock.sql: Retrieves products supplied by Leka Trading with a stock quantity of at least 20.
- OrdersPerCustomer.sql: Retrieves the number of orders for each customer.
- MaxProfitDay2017.sql: Determines the day in the year 2017 when the company recorded the highest profit.
- SalesProfitByDayOfMonth.sql: Shows how sales profit varies by day of the month across all years in the database.
- ProfitForTofuByDayOfMonth.sql: Shows how profit for the product Tofu varies by day of the month across all years in the database.
- DiscountStatsPerCustomer.sql: Shows total discount amount, average discount amount, and the number of transactions for each customer.
- EmployeesWithFewestCustomersQ1_2017.sql: Identifies the three employees who served the fewest customers in the first quarter of 2017.
- FutureServiceAnniversary.sql: Determines whether there are employees who will celebrate their 20th, 25th, 30th, or 40th work anniversaries in the upcoming year.
- AverageAgeByJobTitle.sql: Calculates the average age of employees by job titles.
- MostTransactionsPerYearByEmployee.sql: Retrieves the age, first name, last name, number of transactions, and age of the employee who conducted the most transactions in each year.
- ProductWithHighestUnitPrice.sql: Retrieves the product with the highest unit price.
- ProductWithLeastQuantityInStock.sql: Retrieves products with the least quantity in stock.
- BeverageWithLeastQuantityInStock.sql: Finds the beverage with the least quantity in stock.
- ProductsBelowAvgBeverageStock.sql: Finds products with less than the average quantity of beverages in stock.
- EmployeesMinMaxSalaryByYear.sql: Finding employees who earn the least and the most with division by years.
- CustomerWithHighestTotalDiscount.sql: Finding the customer who received the highest total discount.
- CustomerWithHighestProductQuantity.sql: Finding the customer who purchased the highest quantity of a specific product.
- CustomerWithMostOrders.sql: Determining which customer placed the most orders.
- EmployeeWithMostTransactions2016.sql: Determining which employee had the most transactions in 2016.
- EmployeesMoreCustomersThanKing.sql: Determining which employees serve more customers than the employee with the surname "King".
- EmployeeBonusCalculation.sql: Calculating bonus for employees based on the number of orders they handled in 2017.
- EmployeeSalesSummary.sql: Generating a summary of sales made by each employee in 2018.
- CustomerMonthlySales2017.sql: Generating a summary of monthly sales for each customer in 2017.
- CategoryMonthlySales2017.sql: Summarizes monthly sales for each product category in 2017.
- EmployeeMonthlyTransactions2017.sql: Summarizes monthly transaction counts for each employee in 2017 and calculates cumulative transactions.
- TopSuppliers2018.sql: Retrieves the top 3 suppliers based on the total value of their products sold in 2018.
- TopBeverageSalesEmployees2018.sql: Retrieves the top 3 employees by the total sales value of beverages in 2018.
- TopProductsQ1_2017.sql: Retrieves the top 3 products by sales value for the first quarter of 2017.
- RankProductsBySalesValue.sql: Retrieves the ranking of products by their total sales value.
- TopProductsByInvoiceCount.sql: Retrieves the top 3 products by the number of invoices they appear on.
- TransactionsAndSalesByYearAndPosition.sql: Retrieves transactions count and total sales value by year and employee position.
- ChangSales.sql: Retrieving sales total for the product "Chang" in category 1, grouped by category, product, and customer company.
- HighestQuantityCustomer.sql: Finding the customer who purchased the highest quantity of a specific product.
- MostOrdersCustomer.sql: Determining which customer placed the most orders.
- TopEmployee2016.sql: Determining which employee conducted the most sales transactions in the year 2016.
- CitiesWithEmployeesButNoCustomers.sql: Providing cities where NORTHWIND employees live but where no customer resides.
- CompaniesWithOrdersOneMonthBeforeOldestOrder.sql: Providing the names of companies that placed orders one month before the oldest order.
- MaxQuantityOrderedPerProduct.sql: Providing the maximum quantity of ordered units for each product.
- MaxQuantityPerOrderPerCategory.sql: Providing the maximum quantity of ordered products per order for each product category.
- CheapestProductPerSupplier.sql: Determining the cheapest product from each supplier.
- TopSalesEmployeeByYear.sql: Identifying the top sales employee for each year.
- ShipmentsByCompanyAndYear.sql: Analysing the performance of shipping companies.
Contributions to this repository are welcome! If you have SQL code snippets that you think would be helpful for others, feel free to submit a pull request.
This repository is licensed under the MIT License.