Home > database >  SQL SYNTAX "WHERE" CONDITION NOTATION "(0,1)"
SQL SYNTAX "WHERE" CONDITION NOTATION "(0,1)"

Time:01-24

I'm now learning about Pivoting in SQL, and one of the examples is:

CREATE EXTENSION IF NOT EXISTS tablefunc;
SELECT * FROM CROSSTAB($$
  SELECT
    meal_id,
    DATE_TRUNC('month', order_date) :: DATE AS delivr_month,
    COUNT(DISTINCT order_id) :: INT AS orders
  FROM orders
  WHERE meal_id IN (0, 1)
    AND order_date < '2018-08-01'
  GROUP BY meal_id, delivr_month
  ORDER BY meal_id, delivr_month $$)
  AS ct (meal_id INT,
         "2018-06-01" INT,
         "2018-07-01" INT)
ORDER BY meal_id ASC;

Can you tell me what does WHERE meal_id IN (0, 1) mean? I've tried to search for the answer but can't find any good explanation.

If you could help me, I'll really appreciate it. Thank you...

CodePudding user response:

https://www.w3schools.com/sql/sql_in.asp

Within the brackets, you can specify elements that would otherwise be individually checked by meal_id = 0 and connected by OR-Operator

CodePudding user response:

in operator is used to pass an array set to identify the matching values.

PostgreSQL link

  •  Tags:  
  • Related