<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
select datein,amount,
    
    coalesce(sum(case when item = "vital feed 3mm" then input end), 0) as 3m,
    coalesce(sum(case when item = "vital feed 2mm" then input end), 0) as 2m,
    coalesce(sum(case when item = "vital feed 4mm" then input end), 0) as 4m,
     coalesce(sum(case when item = "vital feed 3mm" then output end), 0) as out3,
    coalesce(sum(case when item = "vital feed 2mm" then output end), 0) as out2,
    coalesce(sum(case when item = "vital feed 4mm" then output end), 0) as out4
from agwa
group by datein
</body>
</html>