SELECT receipt.`date` "Дата/время", receipt_item_properties.value "Номер сертификата"
FROM receipt_item
JOIN receipt ON (receipt.`cash_id` = receipt_item.`cash_id` AND receipt.`id` = receipt_item.`receipt_header`)
JOIN receipt_item_properties ON (receipt_item.`cash_id` = receipt_item_properties.`cash_id` AND receipt_item_properties.`receipt_item` = receipt_item.id)
WHERE receipt.`store` = 22
AND receipt_item.item = 154945
AND receipt_item_properties.`code` = 'ACCOUNT'
ORDER BY receipt.date;
and receipt.`result` = 0
/*create view v_cert_receipt_paid*/
SELECT
receipt.date AS `date_paid`,
receipt.local_number AS `check_number`,
receipt.store AS `store`,
receipt_payment.payment_id,
receipt_payment.`payment_name`,
receipt_payment.`amount`,
receipt_payment.`card_number`
FROM receipt
JOIN `receipt_payment`
ON (`receipt`.`cash_id` = `receipt_payment`.`cash_id` AND `receipt`.`id` = `receipt_payment`.`receipt_header`)
WHERE `receipt`.`result` = 0
AND receipt.date BETWEEN '2022-04-11' AND '2022-04-30'
AND receipt.store = 40
AND receipt_payment.`payment_name` = 'Сертификат';