Loading...
「ツール」は右上に移動しました。
利用したサーバー: natural-voltaic-titanium
0いいね 6回再生

Intro to T-SQL Part 04: Write Subqueries in T-SQL 🔄📊 #sql #sqlserver #tsql

In Part 04 of our Introduction to Transact-SQL series, we’ll explore subqueries! Learn how to write subqueries in T-SQL to make your SQL queries more powerful and efficient. Whether you’re extracting data or filtering results within another query, mastering subqueries will take your SQL skills to the next level. Watch now for practical examples and tips!

🔔 Subscribe for more SQL tutorials and expert tips
👍 If you found this helpful, don’t forget to like, share, and comment!
📢 Have any questions about subqueries in T-SQL? Drop them in the comments!

=================
Queries used in this video:
select max(UnitPrice) from SalesLT.SalesOrderDetail

select name,ListPrice from SalesLT.Productwhere ListPrice &gt (select max(UnitPrice) from SalesLT.SalesOrderDetail)

select distinct ProductID from SalesLT.SalesOrderDetailwhere OrderQty &gt=20

select name,ListPrice from SalesLT.Productwhere ProductID IN(select distinct ProductID from SalesLT.SalesOrderDetailwhere OrderQty &gt=20 )

SELECT distinct name,ListPrice from SalesLT.Product P join SalesLT.SalesOrderDetail o on p.ProductID=o.ProductID
where o.OrderQty &gt=20

select od.SalesOrderID,od.ProductID,od.OrderQty from SalesLT.SalesOrderDetail od
where od.OrderQty = (select max(OrderQty) from SalesLT.SalesOrderDetail as d
where od.ProductID=d.ProductID)
order by od.ProductID

select o.SalesOrderID,o.OrderDate,CustomerID,
(select companyname from SalesLT.Customer c where c.CustomerID=o.CustomerID) as Companyname from SalesLT.SalesOrderHeader o
order by o.SalesOrderID

-- product with a list price of 100 or more that have been sold for less than 100

select ProductID,name, ListPrice from SalesLT.Productwhere ProductID in
(select productid from SalesLT.SalesOrderDetail where UnitPrice &ls=100.00)
and ListPrice &gt= 100.00

-- cost , listprice and avg selling price or each product
select p.ProductID,p.Name,p.StandardCost,p.ListPrice,
( Select AVG(o.UnitPrice) from SalesLT.SalesOrderDetail o where o.ProductID=p.ProductID) as AvgSellingprice
from SalesLT.Product p
order by p.ProductID

-- products that have an average selling price lower than the cost

select p.ProductID,p.Name,p.StandardCost,p.ListPrice,
( Select AVG(o.UnitPrice) from SalesLT.SalesOrderDetail o where o.ProductID=p.ProductID) as AvgSellingprice

from SalesLT.Product p

where StandardCost &gt ( Select AVG(o.UnitPrice) from SalesLT.SalesOrderDetail o where o.ProductID=p.ProductID)
order by p.ProductID

--- Exist predicate

select CustomerID,CompanyName,EmailAddress from SalesLT.Customer c where ( select count(*) from SalesLT.SalesOrderHeader o where o.CustomerID=c.CustomerID) &gt 0

select CustomerID,CompanyName,EmailAddress from SalesLT.Customer c where not exists ( select * from SalesLT.SalesOrderHeader o where o.CustomerID=c.CustomerID)


================
The Power of BI is a YouTube channel that provides educational resources for individuals looking to learn about Power BI, a powerful data visualization tool from Microsoft. The channel offers tutorials for users of all levels, from beginners to advanced users, covering topics such as data analysis and visualization. With a wide range of topics and a focus on clear and concise explanations, the channel is a great resource for anyone looking to improve their data analysis and visualization skills. Whether you're a student, a business professional, or a data enthusiast, the Power of BI channel has something to offer.
#PowerBI
#DataVisualization
#BusinessIntelligence
#DataAnalysis
#DataScience
#BITools
#MicrosoftPowerBI
#ExcelPowerBI

コメント