所以我试图按值排序数据库中的项目,这是一行json编码值的总和。例如,几行看起来像:
id | program_invested_details | program_add_status | program_status
5 | {"invested":"120.00","received":5.4} | 4 | 1
7 | {"invested":"120.00","received":9} | 4 | 1
15 | {"invested":"110.00","received":50} | 4 | 1
52 | {"invested":"110.00","received":2} | 4 | 1
我的查询如下:
SELECT id, ((`common_schema`.`get_option`("program_invested_details", "received") * 100) / `common_schema`.`get_option`("program_invested_details", "invested")) AS PERCENT_TOTAL FROM `hp_programs_list` WHERE `program_add_status` = 4 AND `program_status` = 1 ORDER BY PERCENT_TOTAL DESC
但是在此查询结果与应该的结果不同之后:
mysql> SELECT id, ((`common_schema`.`get_option`("program_invested_details", "received") * 100) / `common_schema`.`get_option`("program_invested_details", "invested")) AS PERCENT_TOTAL FROM `hp_programs_list` WHERE `program_add_status` = 4 AND `program_status` = 1 ORDER BY PERCENT_TOTAL DESC;
+-----+---------------+
| id | PERCENT_TOTAL |
+-----+---------------+
| 314 | NULL |
| 308 | NULL |
| 307 | NULL |
| 302 | NULL |
| 287 | NULL |
| 285 | NULL |
| 280 | NULL |
| 277 | NULL |
| 269 | NULL |
| 319 | NULL |
| 317 | NULL |
+-----+---------------+
11 rows in set (0.00 sec)
所以PERCENT_TOTAL是NULL而不是SUM。问题在哪里?
答案 0 :(得分:0)
mysql> SELECT `common_schema`.`get_option`(`program_invested_details`, 'received') `percent` FROM `admin_hyips_database`.`hp_programs_list` ORDER BY percent DESC LIMIT 10;
+---------+
| percent |
+---------+
| 93.50 |
| 92.13 |
| 91.47 |
| 9.90 |
| 9.19 |
| 9.14 |
| 9.13 |
| 9.02 |
| 9.00 |
| 9.00 |
+---------+
它的工作。删除了双引号并添加了"`"在选择器上。