Grouping Problem

  • Woo Hoo I figured it out!

    SELECT b.number, b.cashdate, SUM(b.cashamt) FROM

    (

    SELECT c.number, c.cashdate, a.cashamt

    FROM

    (

    SELECT number, MAX(cashdate) AS cashdate from arcashha

    GROUP BY number

    ) AS c

    INNER JOIN arcashha a ON c.number = a.number and c.cashdate = a.cashdate

    GROUP BY c.number, c.cashdate, a.cashamt

    ) AS b

    GROUP BY b.number, b.cashdate

    ORDER BY number

  • Wat were u trying to do actually?? is there a question here?

  • Confused. Figured what out? If you figured something out regarding a question you asked, you really should post it in that thread.

  • If you have multiple records with the same value of number, cashdate and cashamt

    in your arcashha table, you will sum only one of that rows.

    I believe this is not desired behaviour (bug) ?

    Do you actually need to sum all cashamt that happened on last cashdate per each number?

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • looks like this post is for this thread. http://qa.sqlservercentral.com/Forums/Topic1263956-1292-1.aspx

    however that query is hella ugly and really could be rewritten to work much faster as you are only working on one table. to really get it nice we would need nice sample data and the desired output.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply