1

I'm trying to write subquery that use a value from parent query.

Like this:

SELECT
    e.id,
    e.name,
    (SELECT COUNT(ea.id)
     FROM employee_attendance ea
     WHERE ea.emp_id == e.id) AS attendance
FROM 
    employee e

Is there anyway to use this in SQLAlchemy subquery ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
wulfnb
  • 111
  • 1
  • 11
  • 1
    Some DBMS's will allow what he is doing. I THINK Microsoft SQL Server will allow this. – Joshua Schlichting Jul 11 '19 at 10:27
  • is this returning an error? Why won't this work? If it returns an error, what is it? I'm not seeing the connection between your problem and python/sqlalchemy specifically. – Joshua Schlichting Jul 11 '19 at 10:47
  • @JoshuaSchlichting in this query employee id from parent query passing to subquey. is this possible in sqlalchemy subquery ? – wulfnb Jul 11 '19 at 11:32

0 Answers0