Question

Want to update status of only those record whose a_msisdn count > 100 on specific date:

mysql> select * from cc_info limit 1;
+----------------------+--------------+--------+------------+-------------+--------------+--------+------------+-------------+---------------------+---------------------+--------------+--------+---------------+
| transaction_id       | a_msisdn     | a_imsi | a_sub_type | a_lang_code | b_msisdn     | b_imsi | b_sub_type | b_lang_code | incoming_timestamp  | process_timestamp   | request_mode | status | retry_counter |
+----------------------+--------------+--------+------------+-------------+--------------+--------+------------+-------------+---------------------+---------------------+--------------+--------+---------------+
| -9223371087585181184 | 923345070688 |        |          0 |           0 | 923333340955 |        |          1 |           0 | 2019-08-04 15:58:42 | 2019-08-04 15:58:49 |            0 |      3 |             0 |

UPDATE (moved from comments)

update cc_info 
set status =4 
where a_msisdn = ( select a_msisdn 
                   from cc_info 
                   where DATE(incoming_timestamp) ='2019-08-04' 
                     AND status = 3 
                   group by a_msisdn 
                   having count(*) > 100 );

But I am getting the error

ERROR 1242 (21000): Subquery returns more than 1 row

Was it helpful?

Solution

update cc_info dst, ( select a_msisdn 
                      from cc_info 
                      where DATE(incoming_timestamp) ='2019-08-04' 
                        AND status = 3 
                      group by a_msisdn 
                      having count(*) > 100 ) src
set dst.status = 4 
where dst.a_msisdn = src.a_msisdn
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top