[thelist] MYSQL - join a table, to itself?

Tris beertastic at gmail.com
Fri Sep 21 07:11:23 CDT 2007

Ello all!
I've got a table that captures users activity on a points spending site.

my statement table has the follwoing fields:

date, points, calcType, userId

calcType is boolean, where 0 = -  AND 1 = +

What I've been asked to do is simply show 3 peices of data:
Total points added
Total poitns spent
Total points left over...

So, I've got a query
SELECT SUM(points) as earned
FROM `statement` as earnedTable
earnedTable.calctype = 1

But I'm convinced there's gotta be away to join the table with itself
and get the calcType = 0 total too...
the final query, I just want 2 fields.. I can work out the thrid myself...

So, any ideas?


Give a man a fish and he'll feed himself for a day.
Give a man a religion and he'll starve to death praying for a fish.

`We are what we pretend to be, so we must be careful what we pretend to be.`
Kurt Vonnegut

`When a person can no longer laugh at himself, it is time for others
to laugh at him.`
Thomas Szasz

More information about the thelist mailing list