So I'm trying to order items in database by value which is sum of one row json encdoded value. For example few rows looks like:
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
and my query looks like:
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
but after this query result is not the same as it should be:
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)
so the PERCENT_TOTAL is NULL instead of SUM. Where is the problem?
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 |
+---------+
its working. Removed double quotes and added "`" on selector.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.