这篇文章主要为大家详细介绍了SQL Server SQL进行排序、分组、统计的10个新技巧分享,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
1.使用排序使数据有序代码如下:
SELECT ZIP FROM Customers GROUP BY ZIP
代码如下:
SELECT ZIP FROM Customers WHERE State = 'KY' GROUP BY ZIP
代码如下:
SELECT ZIP FROM Customers WHERE State = 'KY' GROUP BY ALL ZIP
代码如下:
SELECT ZIP, Count(ZIP) AS KYCustomersByZIP FROM Customers WHERE State = 'KY' GROUP BY ALL ZIP
代码如下:
SELECT ZIP, Count(ZIP) AS Customers FROM Customers GROUP BY ZIP HAVING Count(ZIP) = 1
代码如下:
SELECT OrderID, Sum(Cost * Quantity) AS OrderTotal FROM Orders GROUP BY OrderID
代码如下:
SELECT Customer, OrderNumber, Sum(Cost * Quantity) AS OrderTotal FROM Orders GROUP BY Customer, OrderNumber WITH ROLLUP
代码如下:
SELECT Customer, OrderNumber, Sum(Cost * Quantity) AS OrderTotal FROM Orders GROUP BY Customer, OrderNumber WITH CUBE
代码如下:
SELECT GROUPING(Customer), OrderNumber, Sum(Cost * Quantity) AS OrderTotal FROM Orders GROUP BY Customer, OrderNumber WITH CUBE
本文来自:http://www.q1010.com/179/8381-0.html
注:关于SQL Server SQL进行排序、分组、统计的10个新技巧分享的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:SQL SERVER
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。