Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
¿Cómo acceder a la columna exterior en la subconsulta mysql?

tengo consulta

 SELECT t1.account AS main, t1.id, tmp.* FROM account.account t1 LEFT JOIN ( SELECT tmp1.account, tmp1.lot - tmp2.lot AS nett FROM ( SELECT account, SUM( lot ) AS lot FROM orders WHERE market_date = "2020-07-20" AND `transaction` = 1 AND account = t1.id ) AS tmp1 LEFT JOIN ( SELECT account, SUM( lot ) AS lot FROM orders WHERE market_date = "2020-07-20" AND `transaction` = 2 AND account = t1.id ) AS tmp2 ON tmp1.account = tmp2.account ) tmp ON tmp.account = t1.id;

y el resultado es

 1054 - Unknown column 't1.id' in 'where clause', Time: 0.001000s

¿Cómo acceder a la selección de subconsulta actual t1.id?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede intentar simplemente usar una unión a una subconsulta de un solo nivel en los pedidos:

 SELECT a.account AS main, a.id, COALESCE(o.nett, 0) AS nett FROM account a LEFT JOIN ( SELECT account, SUM(CASE WHEN `transaction` = 1 THEN lot END) - SUM(CASE WHEN `transaction` = 2 THEN lot END) AS nett FROM orders WHERE market_date = '2020-07-20' GROUP BY account ) o ON o.account = a.account;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!