SqlServer_临时表查询和内联子查询的使用;

SqlServer_临时表查询和内联子查询的使用;,第1张

概述<span style="font-size:18px;">功能:查询订单表中每个顾客第一次下订单的订单号和时间;(1)、临时表使用USE AdventureWorks2008GOSELECT soh.CustomerID, MIN(soh.OrderDate) AS OrderDate INTO #MinOrderDates FROM Sales.SalesOrderHeader s
<span >功能:查询订单表中每个顾客第一次下订单的订单号和时间;(1)、临时表使用USE AdventureWorks2008GOSELECT soh.CustomerID,MIN(soh.OrderDate) AS OrderDate	INTO #MinorderDates	FROM Sales.SalesOrderheader soh	GROUP BY soh.CustomerID;SELECT soh.CustomerID,soh.SalesOrderID,soh.OrderDate	FROM Sales.SalesOrderheader soh	JOIN #MinorderDates t	ON soh.CustomerID = t.CustomerID	AND soh.OrderDate = t.OrderDate	GROUP BY soh.CustomerIDDROP table #MinorderDates(2)、内联子查询SELECT soh1.CustomerID,soh1.SalesOrderID,soh1.OrderDate	FROM Sales.SalesOrderheader soh1	WHERE soh1.OrderDate  = (SELECT Min(soh2.OrderDate)				FROM Sales.SalesOrderheader soh2				WHERE soh2.CustomerID = soh1.customerID)	ORDER BY CustomerID;</span>
总结

以上是内存溢出为你收集整理的SqlServer_临时表查询和内联子查询的使用;全部内容,希望文章能够帮你解决SqlServer_临时表查询和内联子查询的使用;所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1169485.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存