Mysql
 sql >> Base de données >  >> RDS >> Mysql

Définir des variables Big Query comme mysql

Vous pouvez utiliser une clause WITH. Ce n'est pas idéal, mais ça fait le travail.

-- Set your variables here
WITH vars AS (
  SELECT '2018-01-01' as from_date,
         '2018-05-01' as to_date
)

-- Then use them by pulling from vars with a SELECT clause
SELECT *
FROM   your_table 
WHERE  date_column BETWEEN
          CAST((SELECT from_date FROM vars) as date)
          AND
          CAST((SELECT to_date FROM vars) as date)

Ou encore moins verbeux :

#standardSQL
-- Set your variables here
WITH vars AS (
  SELECT DATE '2018-01-01' as from_date,
         DATE '2018-05-01' as to_date
)
-- Then use them by pulling from vars with a SELECT clause
SELECT *
FROM your_table, vars 
WHERE date_column BETWEEN from_date AND to_date