2024-08-05 09:29:35 +00:00
|
|
|
WITH RECURSIVE numbers AS (
|
|
|
|
SELECT 1 n
|
|
|
|
UNION ALL
|
|
|
|
SELECT n + 1
|
|
|
|
FROM numbers
|
|
|
|
WHERE n < (
|
|
|
|
SELECT MAX(stickers)
|
|
|
|
FROM buy
|
|
|
|
WHERE entryFk = ?
|
|
|
|
)
|
|
|
|
),
|
|
|
|
labels AS (
|
2024-12-05 05:56:18 +00:00
|
|
|
SELECT ROW_NUMBER() OVER(ORDER BY b.id, num.n) entryLabelNum,
|
2024-08-05 09:29:35 +00:00
|
|
|
i.name,
|
|
|
|
i.`size`,
|
|
|
|
i.category,
|
|
|
|
ink.id color,
|
|
|
|
o.code,
|
|
|
|
b.packing,
|
|
|
|
b.`grouping`,
|
|
|
|
i.stems,
|
|
|
|
b.id,
|
|
|
|
b.itemFk,
|
|
|
|
p.name producer,
|
2024-08-21 06:05:45 +00:00
|
|
|
IFNULL(i2.comment, i.comment) comment
|
2024-08-05 09:29:35 +00:00
|
|
|
FROM buy b
|
|
|
|
JOIN item i ON i.id = b.itemFk
|
|
|
|
LEFT JOIN producer p ON p.id = i.producerFk
|
|
|
|
LEFT JOIN ink ON ink.id = i.inkFk
|
|
|
|
LEFT JOIN origin o ON o.id = i.originFk
|
|
|
|
LEFT JOIN item i2 ON i2.id = b.itemOriginalFk
|
|
|
|
JOIN numbers num
|
|
|
|
WHERE b.entryFk = ?
|
|
|
|
AND num.n <= b.stickers
|
|
|
|
)
|
2024-12-05 05:56:18 +00:00
|
|
|
SELECT *,
|
|
|
|
ROW_NUMBER() OVER(ORDER BY entryLabelNum) buyLabelNum,
|
|
|
|
(SELECT SUM(stickers) FROM buy WHERE entryFk = ?) entryLabels,
|
|
|
|
(SELECT stickers FROM buy WHERE id = ?) buyLabels
|
2024-08-05 09:29:35 +00:00
|
|
|
FROM labels
|
|
|
|
WHERE id = ?
|