def METHOD_NAME(status):
    return (
        db.session.query(
            Event.id.label('event_id'),
            DiscountCode.id.label('discount_code_id'),
            User.id.label('marketer_id'),
            func.sum(Order.amount).label(status + '_sales'),
            func.sum(OrderTicket.quantity).label(status + '_tickets'),
        )
        .filter(Event.id == Order.event_id)
        .filter(Order.marketer_id == User.id)
        .filter(Order.discount_code_id == DiscountCode.id)
        .filter(Order.status == status)
        .group_by(Event)
        .group_by(DiscountCode)
        .group_by(User)
        .group_by(Order.status)
        .cte()
    )