在mysql中使用distinct和order by,但没有删除重复数据

62lalag4  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(335)

我不知道为什么在执行的sql时它没有删除重复的数据

SELECT DISTINCT
    account_id
FROM
    t_profit_sum_archive
WHERE
    profit_id >= 52487444
ORDER BY
    profit_id
LIMIT 10000000;

这是一张table account .

profit_id  account_id     type   am   profit   date_settled      time_create    time_update
    1   4425211956666666666 4     0      0     2018-04-24   2018-05-15 10:57:21 2018-05-15 10:57:21
    2   5422433335611061810 4   3000000 340    2018-04-24   2018-05-15 10:57:21 2018-05-15 10:57:21
    3   3102301983522434928 4     0      0     2018-04-25   2018-05-15 10:57:21 2018-05-15 10:57:21
    4   4425211956666666666 4   3000000 340    2018-04-25   2018-05-15 10:57:21 2018-05-15 10:57:21

我真的不知道为什么?我想可能是因为这个表有太多的数据(78926576行),因为当我测试另一个表(230000行)时,它是正常的。表格结构如下:

profit_id   bigint  
account_id  varchar 
type    char    
am  bigint                  
profit  bigint  
date_settled    date    
time_create datetime    
time_update datetime
zpjtge22

zpjtge221#

使用子查询删除所有重复项,然后获取前10000000条记录。

SELECT 
   A.account_id
FROM
(SELECT DISTINCT
    account_id
FROM
    t_profit_sum_archive
WHERE
    profit_id >= 52487444
ORDER BY
    profit_id) A
LIMIT 10000000;

相关问题