Fikse 10-NULL=NULL
Jeg har et problem når der bliver regnet med NULL, eksempelvis bliver 10-NULL=NULL i stedet for 10-NULL=10, hvordan fikser man det i en query? Her er data og forespørgsel:ORGANISATION
organisation_id | id | antal
222 | 10 | 5
222 | 20 | 2
333 | 10 | 2
STOCK
organisation_id | id | nummer
333 | 10 | 45312
333 | 10 | 45313
333 | 10 | 45314
FORESPØRGSEL
SELECT allocated, onstock, (allocated-onstock) AS to_be_used
FROM (
SELECT antal AS allocated, organisation_id
FROM organisation
GROUP BY organisation_id, id
) a
LEFT JOIN
(
SELECT count(id) AS onstock, organisation_id
FROM stock
GROUP BY id
) b
USING (organisation_id);
Giver noget i retning af:
allocated | onstock | to_be_used
5 | 3 | 2
2 | NULL | NULL
2 | NULL | NULL
??????