ANI: ....e = 3 OR cash.type = 4) HAVING users.status = 3 GROUP BY users.id;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY users.id' at line 1
ANI... ...e = 3 OR cash.type = 4) AND HAVING users.status = 3 GROUP BY users.id;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'HAVING users.status = 3 GROUP BY users.id' at line 1
bo HAVING ma być po GROUP BY, proponuję:
SELECT users.id AS id, SUM((type * 2 - 7) * value) AS balance
FROM users LEFT JOIN cash ON users.id = cash.userid WHERE (cash.type
= 3 OR cash.type = 4) GROUP BY users.id, status HAVING status = 3
ale na postgresie to samo zwraca podawane już przeze mnie:
SELECT users.id AS id, SUM((type * 2 - 7) * value) AS balance
FROM users LEFT JOIN cash ON users.id = cash.userid WHERE (cash.type
= 3 OR cash.type = 4) AND status = 3 GROUP BY users.id
należy jeszcze zauważyć, że zwracają one złe znaki przy liczbach, więc ostatecznie pozostaje następujące zapytanie:
SELECT name, lastname, SUM(-(type * 2 - 7) * value) AS balance
FROM users LEFT JOIN cash ON users.id = cash.userid
WHERE (cash.type = 3 OR cash.type = 4) GROUP BY users.id, name, lastname, status HAVING status = 3 ORDER BY balance
-- Pozdrawiam Aleksander Machniak ( A.L.E.C ) http://k27.prv.pl/alec GG-2275252
uczestnicy (1)
-
A.L.E.C