| | |
| | | FROM tcm_course_purchase_order o |
| | | WHERE o.deleted = 0 |
| | | AND o.course_type = 'HEALTH_COURSE' |
| | | AND o.purchase_target_type = 'COURSE' |
| | | AND o.status = 'PAID' |
| | | AND o.app_user_id = #{appUserId} |
| | | AND o.course_id IS NOT NULL |
| | | AND NOT EXISTS ( |
| | | SELECT 1 |
| | | FROM tcm_course_purchase_order newer |
| | | WHERE newer.deleted = 0 |
| | | AND newer.course_type = 'HEALTH_COURSE' |
| | | AND newer.status = 'PAID' |
| | | AND newer.app_user_id = #{appUserId} |
| | | AND newer.course_id = o.course_id |
| | | AND ( |
| | | IFNULL(newer.paid_at, newer.created_at) > IFNULL(o.paid_at, o.created_at) |
| | | OR ( |
| | | IFNULL(newer.paid_at, newer.created_at) = IFNULL(o.paid_at, o.created_at) |
| | | AND newer.id > o.id |
| | | ) |
| | | ) |
| | | ) |
| | | ORDER BY o.paid_at DESC, o.id DESC |
| | | </select> |
| | | |