Grouping Data

Kuler Master 266 Reputation points
2024-02-14T09:10:13.5133333+00:00

Hello there, I need a help about the SQL Query. Data example:

Date               Amount 
2024-01-11 10:15   1000
2024-01-11 11:10   2000
2024-01-12 10:16   5000
2024-01-13 11:12   4000
2024-01-13 11:18   4000

Expeceted result:

Date        Amount 
2024-01-11  3000
2024-01-12  5000
2024-01-13  8000

Meaning I need to group the items by date (without time) and SUM the amounts. Thank you!

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,203 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,855 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
62 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,591 questions
{count} votes

Accepted answer
  1. Viorel 114.1K Reputation points
    2024-02-14T09:15:22.7066667+00:00

    For example:

    select cast([Date] as date) as [Date], sum(Amount) as Amount
    from MyTable
    group by cast([Date] as date)
    order by [Date]
    

0 additional answers

Sort by: Most helpful