SQL Server簡略完成數據的日報和月報功效。本站提示廣大學習愛好者:(SQL Server簡略完成數據的日報和月報功效)文章只能為提供參考,不一定能成為您想要的結果。以下是SQL Server簡略完成數據的日報和月報功效正文
本文實例講述了SQL Server簡略完成數據的日報和月報功效。分享給年夜家供年夜家參考,詳細以下:
--320, SQL SERVER 日報 --查詢2009-01-01當天客戶A1,A2,A3的定單數目 SELECT Cust_Name , CONVERT(CHAR(10), Order_Date, 120) Order_Date , SUM(Qty) Qty FROM Orders_Big WHERE 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) Qty FROM Orders_Big WHERE 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) Qty FROM Orders_Big WHERE 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, ORACLE SELECT Cust_Name , TO_CHAR(Order_Date, 'YYYY-MM') Order_YrMs --辦法1 --, TRUNC(Order_Date, 'MM') Order_Date--辦法2 , SUM(Qty) Qty FROM Orders_Big WHERE 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')--辦法2 ORDER BY 2, 1
願望本文所述對年夜家SQL Server數據庫法式設計有所贊助。