-- 1. 确认设备和卡
SELECT id, virtual_no, deleted_at
FROM tb_device
WHERE virtual_no = '862639071883120';

SELECT id, iccid, device_virtual_no, deleted_at
FROM tb_iot_card
WHERE iccid IN (
  '89860885192590574651',
  '89860625750010463442',
  '8986112520903882441'
);

-- 2. 确认没有业务数据；这些如果查出数据，先不要直接删
SELECT *
FROM tb_package_usage
WHERE deleted_at IS NULL
  AND (
    device_id IN (SELECT id FROM tb_device WHERE virtual_no = '862639071883120')
    OR iot_card_id IN (
      SELECT id FROM tb_iot_card WHERE iccid IN (
        '89860885192590574651',
        '89860625750010463442',
        '8986112520903882441'
      )
    )
  );

SELECT *
FROM tb_order
WHERE deleted_at IS NULL
  AND (
    device_id IN (SELECT id FROM tb_device WHERE virtual_no = '862639071883120')
    OR iot_card_id IN (
      SELECT id FROM tb_iot_card WHERE iccid IN (
        '89860885192590574651',
        '89860625750010463442',
        '8986112520903882441'
      )
    )
  );

SELECT *
FROM tb_asset_wallet_transaction
WHERE deleted_at IS NULL
  AND asset_wallet_id IN (
    SELECT id FROM tb_asset_wallet
    WHERE asset_id IN (
      SELECT id FROM tb_device WHERE virtual_no = '862639071883120'
      UNION
      SELECT id FROM tb_iot_card WHERE iccid IN (
        '89860885192590574651',
        '89860625750010463442',
        '8986112520903882441'
      )
    )
  );
