View difference between Paste ID: TNv2wt1r and tqzKs2Kk
SHOW: | | - or go back to the newest paste.
1
select t.* , COUNT(DISTINCT `reserved_amount`.`id`) `reserved_amount_task`
2
FROM (SELECT
3
    `t1`.*,
4
    `ti`.`id_task` `task_id_favorite`,
5
    `tm`.`id_task` `task_id_hidden`,
6
    `bw`.`idu` `id_user_white_list`,
7-
    t1.id as t1id
7+
    t1.id as t1id,
8
	t1.amount as t1amount
9
FROM
10
    `tb_task_w` AS `t1`
11
        JOIN
12
    `tb_task_r` `completed` ON `completed`.`id_task` = `t1`.`id` AND `completed`.`status` = 2
13
        LEFT JOIN
14
    `tb_task_i` `ti` ON `ti`.`id_user` = 345437 AND `ti`.`id_task` = `t1`.`id`
15
        LEFT JOIN
16
    `tb_task_m` `tm` ON `tm`.`id_user` = 345437 AND `tm`.`id_task` = `t1`.`id`
17
        LEFT JOIN
18
    `still_block_white` `bw` ON `bw`.`idb` = 345437 AND `bw`.`idu` = `t1`.`id_author`
19
20
WHERE
21
        `t1`.`id` != '' AND `tm`.`id_task` IS NULL AND `completed`.`id_user` = 345437
22-
    `t1`.`id`
22+
) t
23
    LEFT JOIN
24-
    `t1`.`amount` DESC
24+
              `tb_task_r` `reserved_amount` ON `reserved_amount`.`id_task` = `t`.`t1id` AND `reserved_amount`.`status` IN (0,1)
25-
LIMIT 0, 30) t
25+
26
    `t`.`t1id`
27-
              `tb_task_r` `reserved_amount` ON `reserved_amount`.`id_task` = `t`.`t1id` AND `reserved_amount`.`status` IN (0,1)
27+
28
    `t`.`t1amount` DESC
29
LIMIT 0, 30