SUM(IF(aqorders.datereceived IS NULL, aqorders.quantity, 0)) AS expected_items
FROM aqbasket
LEFT JOIN aqorders ON aqorders.basketno = aqbasket.basketno
WHERE booksellerid = ?
WHERE booksellerid = ? AND aqorders.datecancellationprinted IS NULL
GROUP BY aqbasket.basketno
};
my $sth = $dbh->prepare($query);
-