<span style="font-size:18px;">功能:查询订单表中每个顾客第一次下订单的订单号和时间; (1)、临时表使用 USE AdventureWorks2008 GO SELECT 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.CustomerID DROP 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。