The examples in this article describe the daily and monthly features of SQL Server's simple implementation of data. Share to everyone for your reference, specific as follows:
--320, SQL SERVER Daily--Inquires the order quantity of customer a1,a2,a3 on the day of 2009-01-01 SELECT Cust_name, CONVERT (CHAR (), Order_date, 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 corresponds to >= and <= BETWEEN ' 2009-01-01 ' and ' 2009-01-02 '/GROUP by Cust_name, CONVERT (CHAR), order_d Ate,--321) Order by 2, 1. ORACLE Daily-Inquire about the order quantity of customer a1,a2,a3 on the day of 2009-01-01 SELECT Cust_name, To_char (order_date, ' yyyy-mm-dd ') order_date--Method one: Convert to String type--, TRUNC (order_date) Order_date--Method Two: Truncates the time and seconds information, 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, T O_char (order_date, ' yyyy-mm-dd ')--method one--, TRUNC (order_date)--Method two order by 2, 1------------------------------10.2----- ---------------------------------326,sql SERVER Monthly Report SELECTCust_name, convert (char (7), order_date,) order_yrms, CAST (CONVERT (char (7), order_date,) + ' -01 ' as Datetim E) order_date, SUM (Qty) Qty from Orders_big WHERE 1=1 and Cust_name in (' A1 ', ' A2 ', ' A3 ') and order_date >= ' 20 09-01-01 ' and order_date< ' 2009-02-01 ' GROUP by Cust_name, CONVERT (CHAR (7), order_date, the) Order by 2, 1--326,
ORACLE SELECT Cust_name, To_char (order_date, ' yyyy-mm ') order_yrms--Method 1--, TRUNC (order_date, ' MM ') order_date--Method 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 ')--Method 1--, TRUNC (order_date, ' M
M ')--Method 2 ORDER by 2, 1
Hopefully this article will help you with your SQL Server database design.