Skip to content
Advertisement

Aggregating two values in same select statement. Second aggregation is decreasing in value for each row for some reason

I’m currently trying to aggregate two values simultaneously in one select statement; however, the second aggregated value is decreasing for some reason. I know what I’m doing is wrong, but I don’t understand why it’s wrong (assuming it’s the very last code block). Mainly just trying to better understand what’s going on, and why it’s happening.

I already have a corrected query that works (at the bottom)

Note: Query and outputs are simplified, please ignore any syntax issues. Additionally, in real query, I need to keep subscription_start_date field in until the end.

Query with issue (very last block):

Current Output:

Expected Output:

Updated correct query:

Advertisement

Answer

If I understand what you are trying to do, the query is way more complicated than necessary. I think this does what you want:

I would advise you to ask a new question, explaining the logic you want to implement and providing reasonable sample data and desired results.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement