79080054

Date: 2024-10-12 02:00:13
Score: 0.5
Natty:
Report link

So what I needed was a scalar_subquery and use an alias for the sub select that was on the ON matching. The final query statement looked like this...I combined them.

    current_date = str(datetime.date.today())
    aliasEpr= aliased(EmployeePayRate)
    user_sel_stmt = select(User.user_id, User.full_name, User.email, User.phone, 
                           User.locked, User.last_login_date, User.active, 
                           EmployeePayRate.default_charge_rate, EmployeePayRate.pay_rate
    ).outerjoin(
        EmployeePayRate, EmployeePayRate.pay_rate_id == ( 
            select(aliasEpr.pay_rate_id).where(
                and_(
                        aliasEpr.company_id == User.company_id,
                        aliasEpr.user_id == User.user_id,
                        func.date(aliasEpr.start_date) <= current_date
                )
            ).order_by(aliasEpr.start_date.desc()).limit(1).scalar_subquery()
        )).where(
            and_(
                (User.company_id == data["company_id"]) & (or_(*or_conditions))
            )
        )
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: JustMe