easy SQL question

Ivan Smahin IvanSmahin at public.kherson.ua
Thu Oct 13 12:05:20 CDT 2005


Hello Damon,

Thursday, October 13, 2005, 11:38:27 AM, you wrote:

DP> Hi Guys,
 
DP> Not good enough at SQL to figure this out myself.
 
DP> Table with two fields  name & Count
 
DP>             name    count
DP>             John     2
DP>             Ben      3
DP>             John     5
DP>             John     23
DP>             Ben      3
DP>             Ben      7
DP>             John     3
DP>             John     8
 
 
DP> What I want is this returned 
 
DP> John     41
DP> Ben      13
 
DP> I have read up on unique and distinct but cannot figure it out, the SUM
DP> bit is easy but I think I have to have one call for each person
 
DP> select SUM(count) from data where name="John"
DP> select SUM(count) from data where name="Ben"
 
DP> and there could be hundreds of names , so this would be BAD.
 
select name, SUM(count) from data GROUP BY name

BTW,  It  would  be  better  to  have  another  field name rather then
"count". SQL-parser might be confused with it because it is keyword.


-- 
Best regards,
 Ivan                            mailto:IvanSmahin at public.kherson.ua



More information about the Valentina mailing list