tags:

views:

56

answers:

3

I'm trying to calculate some columns in a mysql database with this code:

"SELECT SUM(klick) FROM svar GROUP BY pollid HAVING pollID="& rstPoll("PollId")

But it doesn't work. So what I want to do is to get the sum of all "klick" where a pollId has a certain value. I got this code to work with access but not with mysql:

"SELECT SUM(klick) FROM svar WHERE pollID="& rstPoll("PollId"))

Some lines in the database: id: 180 klick: 10 pollid: 56

id: 181 klick: 53 pollid: 56

id: 182 klick: 10 pollid: 56

Now I want the sum of all the klick where pollId = 56 for example. So the results here would be: 73

+2  A: 

to just get the sum of klick for a particular pollID you don’t need a group by clause:

SELECT SUM(klick)
  FROM svar
 WHERE pollID = %d
knittl
Doesn't work :( thank you anyway
i think i got your question wrong. what exactly do you want as a result? can you show an example table with few lines and the expected result?
knittl
some lines in the databaseid: 180klick: 10pollid: 56id: 181klick: 53pollid: 56id: 182klick: 10pollid: 56Now I want the sum of all the klick where pollId = 56 for example. So the results here would be: 73
Thank you very much for your help, I'm sorry I can't vote for your answer but I haven't registered me yet.
+2  A: 

I don't know what this rstPoll() business is but this is entirely valid MySQL SQL:

SELECT SUM(klick) FROM svar WHERE pollID = 1234

assuming pollID is a numeric type. And it will do what you expect so you've got something else going on.

cletus
This works now. Wow. I don't know why it didn't work before.I'm sorry for asking this stupid question but thank you everyone for the answers, they helped me very much.
+1  A: 

Your second query is correct. You must have a problem comparing two different types: pollID and whatever rstPoll("PollId") returns.

Nestor