i currently have this sql code
SELECT f.ID, f.name, l.name as location,
SUM( s.created ) AS produced,
SUM( s.amount ) AS total,
(SUM( s.created ) / SUM( s.amount ) *100) AS percent
FROM factories AS f
LEFT JOIN stockf AS s ON f.ID = s.factoryid
LEFT JOIN locations AS l ON f.location = l.ID
WHERE (f.owner =".clean($_COOKIE['toptycoons']['i'])." AND f.approved = 1)
GROUP BY f.ID
ORDER BY f.name ASC
which does almost what i want it to do, lists the factory id, name, location, the total items produced, total ordered and what percentage has been completed
ID || name || location || produced || total || percent
1 || fact 1 || loc 1 || 124 || 125 || 99
2 || fact 2 || loc 1 || NULL || NULL || NULL
What i want is it to not include the completed stock (so if s.completed =1)
i tried changing part of the sql to
WHERE (f.owner =".clean($_COOKIE['toptycoons']['i'])." AND f.approved = 1 AND s.completed = 0)
but it then ignores the second factory (fact 2)
so it show it like this
ID || name || location || produced || total || percent
1 || fact 1 || loc 1 || 24 || 25 || 96
2 || fact 2 || loc 1 || NULL || NULL || NULL
is it possible to change the sql to do this and how would i?