SQL Server simple implementation of data daily and monthly functions _mssql

Source: Internet
Author: User
Tags time and seconds

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.