- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
DROP PROCEDURE IF EXISTS postgkh.ACCOUNT_ITM $$
CREATE PROCEDURE postgkh.ACCOUNT_ITM(IN PERIOD DATE, IN ACC_ID INT)
BEGIN
SELECT A.ACCOUNT_ID, A.ACCOUNT_NO
# Смачный кусок кода
(SELECT GROUP_CONCAT(document_no ORDER BY document_no SEPARATOR ', ') DOCUMENT_NO
FROM
(SELECT d.document_no document_no
FROM postgkh.docar dr INNER JOIN
postgkh.document d ON dr.document_id = d.document_id
WHERE dr.account_id = ACC_ID
AND d.document_fromdate <= LAST_DAY(PERIOD)
AND (d.DOCUMENT_CLOSEDATE >= PERIOD OR d.DOCUMENT_CLOSEDATE IS NULL)
) d
) DOCUMENT_NO
FROM postgkh.ACCOUNT
WHERE A.ACCOUNT_ID = ACC_ID
GROUP BY A.ACCOUNT_ID
LIMIT 1;
END $$