Skip to content

Instantly share code, notes, and snippets.

@hdemon
Created November 18, 2011 10:13
Show Gist options
  • Save hdemon/1376075 to your computer and use it in GitHub Desktop.
Save hdemon/1376075 to your computer and use it in GitHub Desktop.
MySQLでは自己相関サブクエリが使えないらしいので、内部結合を使って自分のテーブル内のカラムを集計し、別のカラムに入れる。
UPDATE movie_log
INNER JOIN (
SELECT
item_id,
date,
view +
(
comment *
(
(view + mylist) / (view + comment + mylist)
)
) + mylist * 15 AS calculated_point
FROM movie_log
) AS temp
ON movie_log.item_id = temp.item_id
AND movie_log.date = temp.date
SET movie_log.point = calculated_point;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment