Search code examples
sqlansi-sql

SELECT any FROM system


Can any of these queries be done in SQL?

SELECT dates FROM system 
WHERE dates > 'January 5, 2010' AND dates < 'January 30, 2010'

SELECT number FROM system 
WHERE number > 10 AND number < 20

I'd like to create a generate_series, and that's why I'm asking.


Solution

  • I assume you want to generate a recordset of arbitrary number of values, based on the first and last value in the series.

    In PostgreSQL:

    SELECT  num
    FROM    generate_series (11, 19) num
    

    In SQL Server:

    WITH    q (num) AS
            (
            SELECT  11
            UNION ALL
            SELECT  num + 1
            FROM    q
            WHERE   num < 19
            )
    SELECT  num
    FROM    q
    OPTION (MAXRECURSION 0)
    

    In Oracle:

    SELECT  level + 10 AS num
    FROM    dual
    CONNECT BY
            level < 10
    

    In MySQL:

    Sorry.