English 中文(简体)
MySQL根据其原有价值变更价值
原标题:MySQL change a value depending on its original value

Hy everyone, Long time reader, first time poster.

这种声音应当非常简单,但我无法在任何地方找到解决办法。 我在建立评级制度时,如果某种情况是活跃的,人们可以进行评级。 它有自己的微薄逻辑,但我需要这样做。

  1. check the items rating
  2. depending on the current rating change it to a pre set amount.

我用2个卡勒克语,但我相信,采用单一存储程序(一个可以投票,另一个可以投否决票)将大大加快。

表格:

item_id | item_rating
---------------------
   10   |    1

赞成:

if | then
---------
 0 |  1
 1 |  2
-1 |  1
-2 |  1
 2 |  2

赞成:

if | then
---------
 0 | -1
 1 | -1
-1 | -2
-2 | -2
 2 | -1

我知道一个简单的基于点的系统会比较容易,但由于系统的性质,这是我可以找到的最简单解决办法。

是否有人解释一下我如何利用国际自由论坛的声明来做到这一点? 我确信,答案对知情的人来说确实是显而易见的。

(两次使用MySQL最新版本)

最佳回答

你们是否回想? ::

UPDATE rating
SET item_rating = IF(item_rating < 1, 1, 2);

::

UPDATE rating
SET item_rating = IF(item_rating > -1, -1, -2);
问题回答

这是未经测试的,但我认为它应当发挥作用。

update items i
set item_rating = (select i.item_rating + `then` from item_rating
                   where `if` = i.item_rating)
where i.item_id = 10




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签