Mysql 如何找到被sql打断的练习者?

Mysql 如何找到被sql打断的练习者?,mysql,Mysql,我有一张像这样的桌子: person_id, pe_year, exercise_keep_year 1001, 2016, 12 1001, 2018, 14 1002, 2017, 5 1002, 2018, 0 1003, 2016, 10 1003, 2017, 0 1003, 2018, 1 1003, 2019, 2 如果这个人每年都坚持锻炼,那么体育锻炼年和锻炼年将是相等的。(比如person\u id=1001,exercise\u start\u year=2016-12=2

我有一张像这样的桌子:

person_id, pe_year, exercise_keep_year
1001, 2016, 12
1001, 2018, 14
1002, 2017, 5
1002, 2018, 0
1003, 2016, 10
1003, 2017, 0
1003, 2018, 1
1003, 2019, 2
如果这个人每年都坚持锻炼,那么体育锻炼年和锻炼年将是相等的。(比如person\u id=1001,exercise\u start\u year=2016-12=2018-14=2004)

如果运动被中断,体育年和运动年并不完全相同。(如person_id=1003)

我要找到练习被打断的所有人的id。请怎么做?

试试这个

select person_id from
(select person_id,count(distinct(pe_year-exercise_keep_year)) as cnt from tablename group by person_id) as a
where cnt>1
试试这个

select person_id from
(select person_id,count(distinct(pe_year-exercise_keep_year)) as cnt from tablename group by person_id) as a
where cnt>1
从t中选择人员id
按人分组\u id
有计数(不同的pe年-运动保持年)1
从t中选择人员id
按人分组\u id
有计数(不同的pe年-运动保持年)1