T-SQL queries for data with a column with a total value greater than X

Source: Internet
Author: User

Original: https://www.lesg.cn/netdaima/sqlservert-sql/2016-459.html

Today, the operation of the query encountered a request such as:

There is a table

User ID Date of purchase Purchase Amount Purchase status
1 2016-10-12 100 1
2 2016-11-12 10 1
2 2016-11-15 100 1

Need to check out 11-12 to 11-15 period, the total purchase amount is greater than 105;

Query SQL as follows (need to use the having function)

Select User ID,Sum(purchase amount) from    twhere buy date >=' 2016-11-12 '  and purchase date <='2016-11-15 23:59 59.00'group  by havesum>

T-SQL queries for data with a column with a total value greater than X

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.