开发者

adding values before mysql extraction or after?

Say this is our sql statement

SELECT points, value
FROM table WHERE x = y

This returns something like this

points  |  color
  5         red
  11        red
  2         blue
  9         blue

I would now like to add the points of the color "red" and add the points of color "blue". And then update the table with the new points.

What is the best approach for this? or is this better solved in a mysql statement before e开发者_开发问答xtraction?


Maybe you want this?

SELECT SUM(points) AS points, value
FROM yourtable
WHERE x = y
GROUP BY value

If you need to update the table you can store this result in a tempoary table and then either rename the tables or delete all rows from the original table and then copy them from the temporary table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜