sql >> Database teknologi >  >> RDS >> Mysql

Indstilling af Big Query-variabler som mysql

Du kan bruge en WITH-klausul. Det er ikke ideelt, men det får jobbet gjort.

-- 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)

Eller endnu mindre ordrig:

#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


  1. Konverter String ISO-8601 dato til oracles tidsstempel datatype

  2. JSON_SEARCH() – Find stien til en streng i et JSON-dokument i MySQL

  3. DNA vs moderne sikkerhedskopieringsmetoder:Fremtiden for datalagring

  4. 2 måder at se, om forældede funktioner stadig bliver brugt i en SQL Server-instans