-- 所有宠物ID + 对应记录总数（去重前）
SELECT 
    (data->>'ID')::INT AS pet_id,  -- 宠物ID
    COUNT(*) AS total_records      -- 该宠物的总持有记录数
FROM "player_pet"
WHERE data->>'ID' IS NOT NULL  -- 过滤无宠物ID的无效记录
GROUP BY (data->>'ID')::INT
ORDER BY total_records DESC, pet_id ASC;  -- 按数量降序、ID升序排列