By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select version();
version() |
---|
8.0.19 |
CREATE TABLE orders (orders_id INT, orders_qty VARCHAR(8), delivery_date DATE, order_status INT);
INSERT INTO orders VALUES
(1 , '2,2,' , '2019-02-01' , 6 ),
(2 , '2,2,' , '2020-02-05' , 6 ),
(3 , '1,' , '2020-02-05' , 6 );
SELECT * FROM orders;
orders_id | orders_qty | delivery_date | order_status |
---|---|---|---|
1 | 2,2, | 2019-02-01 | 6 |
2 | 2,2, | 2020-02-05 | 6 |
3 | 1, | 2020-02-05 | 6 |
SET @order_status:=6;
SET @delivery_date_from:=2019;
SET @delivery_date_till:=2020;
SELECT YEAR(delivery_date) AS `year`,
GROUP_CONCAT(orders_qty SEPARATOR '') AS orders_qty
FROM orders
WHERE order_status = @order_status
AND YEAR(delivery_date) BETWEEN @delivery_date_from
AND @delivery_date_till
GROUP BY YEAR(delivery_date);
year | orders_qty |
---|---|
2019 | 2,2, |
2020 | 2,2,1, |