Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Temporary columns - problem z warunkiem
Forum PHP.pl > Forum > Bazy danych > MySQL
ekstro
Cześć, mam taki problem:

  1. SELECT t1.id, t1.op_name,
  2.  
  3. @invoice_sum_tax:=(SELECT sum((b1.price_base*b1.quantity)*(b3.rate+1)) FROM t24_invoices_elements AS b1 LEFT JOIN t24_taxes AS b3 ON b3.id = b1.code_taxes WHERE code_invoices = t1.id ) AS invoice_sum_tax,
  4.  
  5. @payments_sum:=(SELECT sum(c1.value) FROM t24_payments_list AS c1 WHERE c1.code_invoices = t1.id) AS payments_sum,
  6.  
  7. (@invoice_sum_tax-@payments_sum ) AS saldo
  8.  
  9. FROM (t24_invoices AS t1) LEFT JOIN t24_customers AS t2 ON t2.id=t1.code_customers


i teraz nie działa ani WHERE saldo > 0 ani HAVING > 0

Będę wdzięczny za pomoc w tej kwestii.
dymsza
  1. SELECT * FROM (SELECT t1.id, t1.op_name,
  2.  
  3. @invoice_sum_tax:=(SELECT sum((b1.price_base*b1.quantity)*(b3.rate+1)) FROM t24_invoices_elements AS b1 LEFT JOIN t24_taxes AS b3 ON b3.id = b1.code_taxes WHERE code_invoices = t1.id ) AS invoice_sum_tax,
  4.  
  5. @payments_sum:=(SELECT sum(c1.value) FROM t24_payments_list AS c1 WHERE c1.code_invoices = t1.id) AS payments_sum,
  6.  
  7. (@invoice_sum_tax-@payments_sum ) AS saldo
  8.  
  9. FROM (t24_invoices AS t1) LEFT JOIN t24_customers AS t2 ON t2.id=t1.code_customers ) AS t1 WHERE t1.saldo >0
ekstro
Dzięki!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.