SELECT DISTINCT tovar.name_tovar'Наименование продукции', tovar.lotok'Шт', tovar.price'Цена',
max(CASE id_tochka WHEN 1 THEN kol ELSE '' END) AS 'Маг 1',
max(CASE id_tochka WHEN 2 THEN kol ELSE '' END) AS 'Маг 2',
max(CASE id_tochka WHEN 3 THEN kol ELSE '' END) AS 'Маг 3'
FROM tovar
LEFT JOIN zakaz ON zakaz.id_tovar = tovar.id AND zakaz.data_zap='2022-12-14'
WHERE tovar.id_razdel=2
GROUP BY zakaz.id_tovar
ORDER BY tovar.sort, tovar.id ASC;
max(CASE WHEN id_tochka = 4 THEN kol ELSE '' END) AS 'Маг 1',
max(CASE WHEN id_tochka = 5 THEN kol ELSE '' END) AS 'Маг 2'
SELECT DISTINCT tovar.name_tovar'Наименование продукции', tovar.lotok'Шт', tovar.price'Цена'
FROM tovar
LEFT JOIN zakaz ON zakaz.id_tovar = tovar.id AND zakaz.data_zap='2022-12-14'
WHERE tovar.id_razdel=2
ORDER BY tovar.sort, tovar.id ASC;
SELECT tovar.name_tovar'Наименование продукции', tovar.lotok'Шт', tovar.price'Цена',
max(CASE WHEN id_tochka = 4 THEN kol ELSE '' END) AS 'Маг 1',
max(CASE WHEN id_tochka = 5 THEN kol ELSE '' END) AS 'Маг 2'
FROM tovar
LEFT JOIN zakaz ON zakaz.id_tovar = tovar.id AND zakaz.data_zap='2022-12-14'
WHERE tovar.id_razdel=2
GROUP BY id_tovar
ORDER BY tovar.sort, tovar.id ASC;
- zakaz.data_zap='2022-12-14' перенесли в JOIN
- вместо MAX(CASE -> SUM(CASE