filmov
tv
SQL Server Practice Activity - Which orders have got both hot and cold items? Pivot and Subqueries
Показать описание
How can we look at conditions in multiple rows at the same time?
My SQL Server Udemy courses are:
----
In this video, we have a number of orders (with an OrderID). In each order, customers have the option of ordering hot or cold items. How can we find all of the orders which includes both hot and cold items?
If you want to try this as an SQL Server Practice Activity, then please use the code below. You should find multiple ways of doing so. In this video:
1. We'll use two subqueries in the WHERE clause,
2. we'll use PIVOT, so that Hot and Cold will be in separate columns and
3. we'll use a subquery in the FROM clause, together with SELECT DISTINCT.
----
Here is the code to create the table. If you are using SQL Server 2014 or earlier, then omit the first line.
DROP TABLE IF EXISTS Orders
CREATE TABLE Orders
(OrderID int,
OrderType varchar(20),
OrderCost decimal(7,2))
INSERT INTO Orders VALUES
(1, 'Hot', 4.56),
(1, 'Cold', 1.24),
(2, 'Hot', 5.12),
(3, 'Cold', 0.99),
(4, 'Hot', 4.54),
(4, 'Hot', 6.98),
(4, 'Cold', 2.24);
SELECT *
FROM Orders
My SQL Server Udemy courses are:
----
In this video, we have a number of orders (with an OrderID). In each order, customers have the option of ordering hot or cold items. How can we find all of the orders which includes both hot and cold items?
If you want to try this as an SQL Server Practice Activity, then please use the code below. You should find multiple ways of doing so. In this video:
1. We'll use two subqueries in the WHERE clause,
2. we'll use PIVOT, so that Hot and Cold will be in separate columns and
3. we'll use a subquery in the FROM clause, together with SELECT DISTINCT.
----
Here is the code to create the table. If you are using SQL Server 2014 or earlier, then omit the first line.
DROP TABLE IF EXISTS Orders
CREATE TABLE Orders
(OrderID int,
OrderType varchar(20),
OrderCost decimal(7,2))
INSERT INTO Orders VALUES
(1, 'Hot', 4.56),
(1, 'Cold', 1.24),
(2, 'Hot', 5.12),
(3, 'Cold', 0.99),
(4, 'Hot', 4.54),
(4, 'Hot', 6.98),
(4, 'Cold', 2.24);
SELECT *
FROM Orders
SQL Server Practice Activity - Which orders have got both hot and cold items? Pivot and Subqueries
Practice Activity - Retrieving the last row for each group in a table in SQL Server
5 Best SQL Websites to Practice n Learn Interview Questions for FREE
Practice Activity: What rows in an SQL Server table are not included in a second table?
BEST Websites to Learn SQL FAST 🏃🏽♂️💨
Top 5 Websites to Practice SQL
Practice Activity - remove duplicate rows in SQL Server (three different ways)
Practice Activity: Replacing NULL and blank values in Microsoft SQL Server
SQL Practice 7 | Scholarly things
Practice Activity - Creating a rolling total over the last 3 months in SQL Server
SQL indexing best practices | How to make your database FASTER!
Practice SQL using these two websites !!
SQL Tricks | You Must Try This ! Windows Functions
Practice Activity: Divide dates into 3 months (quarters) periods
Practice SQL Like A Pro 😃🔥
Performance Tuning In MS SQL Server | Real Time MS SQL DBA Issues Part1
6 SQL Joins you MUST know! (Animated + Practice)
SQL Complete Course 2022 | The Basics of SQL | Only Practical Exercises, No Theory
SQL Server Interview Questions and Answers :- What to prepare ?
Learn Basic SQL in 15 Minutes | Business Intelligence For Beginners | SQL Tutorial For Beginners 1/3
TOP 5 free Platforms to Practice SQL (I recommend to you)
Do THIS instead of watching endless tutorials - how I’d learn SQL FAST in 2024
SQL Tutorial for Beginners
Data Analysis SQL Interview Questions | Running SUM | Who Hit the Sales Target First
Комментарии