I have the following table which you can also find in the SQL Fiddle
here:
CREATE TABLE Flows (
Flow_Date DATE,
Product TEXT,
FlowType TEXT,
Country TEXT,
Quantity VARCHAR(255)
);
INSERT INTO Flows
(Flow_Date, Product, FlowType, Country, Quantity)
VALUES
("2019-05-23", "Product A", "Inbound", "DE", "400"),
("2019-05-23", "Product A", "Inbound", "DE", "400"),
("2019-05-23", "Product B", "Inbound", "NL", "500"),
("2019-05-23", "Product B", "Inbound", "NL", "500"),
("2019-05-23", "Product A", "Outbound", "FR", "300"),
("2019-05-23", "Product A", "Outbound", "FR", "300"),
("2019-05-23", "Product B", "Outbound", "US", "200"),
("2019-05-23", "Product B", "Outbound", "US", "200"),
("2019-05-24", "Product A", "Inbound", "DE", "900"),
("2019-05-24", "Product A", "Inbound", "DE", "900"),
("2019-05-24", "Product B", "Inbound", "NL", "800"),
("2019-05-24", "Product B", "Inbound", "NL", "800"),
("2019-05-24", "Product A", "Outbound", "FR", "650"),
("2019-05-24", "Product A", "Outbound", "FR", "650"),
("2019-05-24", "Product B", "Outbound", "US", "450"),
("2019-05-24", "Product B", "Outbound", "US", "450"),
("2019-05-25", "Product A", "Inbound", "DE", "900"),
("2019-05-25", "Product A", "Inbound", "DE", "900"),
("2019-05-25", "Product B", "Inbound", "NL", "800"),
("2019-05-25", "Product B", "Inbound", "NL", "800"),
("2019-05-25", "Product A", "Outbound", "FR", "650"),
("2019-05-25", "Product A", "Outbound", "FR", "650"),
("2019-05-25", "Product B", "Outbound", "US", "450"),
("2019-05-25", "Product B", "Outbound", "US", "450"),
("2019-05-26", "Product A", "Inbound", "DE", "900"),
("2019-05-26", "Product A", "Inbound", "DE", "900"),
("2019-05-26", "Product B", "Inbound", "NL", "800"),
("2019-05-26", "Product B", "Inbound", "NL", "800"),
("2019-05-26", "Product A", "Outbound", "FR", "650"),
("2019-05-26", "Product A", "Outbound", "FR", "650"),
("2019-05-26", "Product B", "Outbound", "US", "450"),
("2019-05-26", "Product B", "Outbound", "US", "450");
I use the following query to get data from this table:
SELECT Flow_Date, Product, FlowType, Country
FROM Flows
WHERE Flow_Date BETWEEN ("2019-05-23 00:00:00") AND ("2019-05-25 23:59:59")
AND Country IN ("DE","NL")
GROUP BY 1,2,3,4;
All this works perfectly so far.
However, now I want to set a variable for the IN
condition in the WHERE
clause of the statement.
Therefore, I tried to go with the following:
SET @country = ("DE", "NL");
SELECT Flow_Date, Product, FlowType, Country
FROM Flows
WHERE Flow_Date BETWEEN ("2019-05-23 00:00:00") AND ("2019-05-25 23:59:59")
AND Country IN @country
GROUP BY 1,2,3,4;
However, with this I get error Operand should contain 1 column(s)
.
What do I need to change in my code to make it work?