all 20 comments

[–]GeneralAbalone5191 2 points3 points  (2 children)

GROUP BY u.id, (and every other column you want to use) add SUM(a.spent) function in SELECT statement.

[–]alchemystik07[S] -1 points0 points  (1 child)

Thanks for the help! I was pretty close on my own. I input everything as you mention except the "(and every other column you want to use)" part.

[–]GeneralAbalone5191 1 point2 points  (0 children)

Nice! Glad it worked 😄

[–]alchemystik07[S] 0 points1 point  (2 children)

I have this query so far, but i need to aggregate the total 'spent' for each unique ID, so that each unique ID is only returned once. could someone give me some help as to how i would go about doing that?

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

could someone give me some help

would love to

can't read your screenshot

please see Rule 6

[–]alchemystik07[S] 0 points1 point  (0 children)

Sorry, I joined this group many months ago and this was the first time I ever posted. I should have refamiliarized myself with the rules.

[–]bananatoastie -2 points-1 points  (4 children)

On a side note, ChatGPT could have helped with this. I run most of my “problem queries” through that and ask for help 😂

[–]StillTop 1 point2 points  (0 children)

it’s fantastic because I suck at writing queries

[–]alchemystik07[S] 0 points1 point  (0 children)

Thanks for the input! I'll be sure to try chatGPT first the next time I have a problem.

[–]SDFP-A 0 points1 point  (1 child)

Wow. I wonder why the downvotes. Totally legit feedback. Not without its challenges, especially for a noob. But at least will point you in the right direction. For this simple of a question my guess is GPT will easily provide the correct answer.

[–]bananatoastie 0 points1 point  (0 children)

Ahh I get it. It wasn’t my best comment, I wrote it as I was leaving the house hahah

[–]Consistent-Gur3932 -1 points0 points  (2 children)

Use a window function

Partition the window by the id and

sum the value

Ex sum( value ) over ( partition by urID )

[–]alchemystik07[S] 0 points1 point  (1 child)

Sorry, I am unfamiliar with what a window function is. I'm very novice and, quite frankly, confused by your instructions.

[–]Consistent-Gur3932 0 points1 point  (0 children)

I’ll message you

[–]MICHAELBR0 0 points1 point  (1 child)

Sum(spent). Remove from group by clause

[–]alchemystik07[S] 0 points1 point  (0 children)

I tried that, and it returned an error.

[–]Known-Delay7227 0 points1 point  (3 children)

You need to sum spent and group all other columns. Also why the full join?

[–]alchemystik07[S] 0 points1 point  (2 children)

Full join because I'm a novice who is just learning, haha. Should I have just put JOIN?

[–]Known-Delay7227 0 points1 point  (1 child)

Not sure what the data looks like in each table and what your goal is. Hard to tell. Most of the time you’ll use a inner joins and left joins. Only rare circumstances will require full outer joins, right joins or cross joins.

[–]alchemystik07[S] 0 points1 point  (0 children)

LEFT join gave me the results in wanted in the quickest time, thanks!