本文实例讲述了SQLServer简单实现数据的日报和月报功能。分享给大家供大家参考,具体如下:--320,SQLSERVER日报--查询2009-01-01当天客户A1,A2,A3的订单数量SELECTCust_Name,CONVERT(CHAR(10),Order_Date,120)Order_Date,SUM(Qty)QtyFROMOrders_BigWHERE1=1ANDCust_NameIN('A1','A2','A3')ANDOrder_Date>='2009-01-01'ANDOrder_Date<'2009-01-02'/*ANDOrder_Date--BETWEEN...AND相当于>=和<=BETWEEN'2009-01-01'AND'2009-01-02'*/GROUPBYCust_Name,CONVERT(CHAR(10),Order_Date,120)ORDERBY2,1--321.ORACLE日报--查询2009-01-01当天客户A1,A2,A3的订单数量SELECTCust_Name,TO_CHAR(Order_Date,'YYYY
本文实例讲述了SQL Server简单实现数据的日报和月报功能。分享给大家供大家参考,具体如下:
--320, SQL SERVER 日报--查询2009-01-01当天客户A1,A2,A3的订单数量SELECT Cust_Name , CONVERT(CHAR(10), Order_Date, 120) Order_Date , SUM(Qty) QtyFROM Orders_BigWHERE 1=1 AND Cust_Name IN ('A1', 'A2', 'A3') AND Order_Date >= '2009-01-01' AND Order_Date<'2009-01-02' /*AND Order_Date -- BETWEEN...AND相当于>=和<= BETWEEN '2009-01-01' AND '2009-01-02'*/GROUP BY Cust_Name , CONVERT(CHAR(10), Order_Date, 120)ORDER BY 2, 1--321. ORACLE 日报--查询2009-01-01当天客户A1,A2,A3的订单数量SELECT Cust_Name , TO_CHAR(Order_Date, 'YYYY-MM-DD') Order_Date --方法一:转换成字符串类型 --, TRUNC(Order_Date) Order_Date --方法二:将时分秒信息截断 , SUM(Qty) QtyFROM Orders_BigWHERE 1=1 AND Cust_Name IN ('A1', 'A2', 'A3') AND Order_Date >= DATE'2009-01-01' AND Order_Date<DATE'2009-01-02'GROUP BY Cust_Name , TO_CHAR(Order_Date, 'YYYY-MM-DD')--方法一 --, TRUNC(Order_Date)--方法二ORDER BY 2, 1------------------------------10.2--------------------------------------326,SQL SERVER 月报SELECT Cust_Name , CONVERT(CHAR(7), Order_Date, 120) Order_YrMs , CAST(CONVERT(CHAR(7), Order_Date, 120) + '-01' AS DATETIME) Order_Date , SUM(Qty) QtyFROM Orders_BigWHERE 1=1 AND Cust_Name IN ('A1', 'A2', 'A3') AND Order_Date >= '2009-01-01' AND Order_Date<'2009-02-01'GROUP BY Cust_Name , CONVERT(CHAR(7), Order_Date, 120)ORDER BY 2, 1--326, ORACLESELECT Cust_Name , TO_CHAR(Order_Date, 'YYYY-MM') Order_YrMs --方法1 --, TRUNC(Order_Date, 'MM') Order_Date--方法2 , SUM(Qty) QtyFROM Orders_BigWHERE 1=1 AND Cust_Name IN ('A1', 'A2', 'A3') AND Order_Date >= DATE'2009-01-01' AND Order_Date<DATE'2009-02-01'GROUP BY Cust_Name , TO_CHAR(Order_Date, 'YYYY-MM')--方法1 --, TRUNC(Order_Date, 'MM')--方法2ORDER BY 2, 1
希望本文所述对大家SQL Server数据库程序设计有所帮助。
标签: SQLServer 简单 实现 数据 日报 月报 功能
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!