mysql - #1054 - Unknown column 'XXXX' in 'where clause' -
how refer parent query column in subquery ? here query
select c.username, c.staff_of, concat(c.first_name, ' ', c.middle_name, ' ', c.last_name ) csr, d.date, d.account, d.total_transaction, d.total_participate, d.total_amount, (select count(id) users created_by = c.username ) total_agents `users` c, (select date(res_date) date, b.res_account account, count(b.res_id) total_transaction, count(distinct(b.res_account)) total_participate, sum(b.res_amount) total_amount merchant_responses b b.res_account in (select t.staff_of users t t.created_by = c.username) ) d c.account_type ='dso' group c.username and result getting
#1054 - unknown column 'c.username' in 'where clause' how make c.username visible in subquery?
thanx in advance
why using subtable? use aggregate function sum there no group statement, think can write that
select c.username, c.staff_of, concat(c.first_name, ' ', c.middle_name, ' ', c.last_name ) csr, date(b.res_date) date, b.res_account account, count(b.res_id) total_transaction, count(distinct(b.res_account)) total_participate, sum(b.res_amount) total_amount, (select count(id) users created_by = c.username ) total_agents `users` c, merchant_responses b b.res_account in (select t.staff_of users t t.created_by = c.username) , c.account_type ='dso' group c.username a join between c , b missing, can't add because don't know keys
Comments
Post a Comment