Задать вопрос
Ответы пользователя по тегу SQL
  • Как правильно составить запрос по выбору дней из диапазона дат?

    frost18
    @frost18 Автор вопроса
    Программист PHP
    SELECT DATE_ADD(date_from, INTERVAL rn DAY) AS `date`
    FROM task
    INNER JOIN (
      SELECT @rn := @rn + 1 AS rn
      FROM (
        SELECT *
        FROM (
          SELECT 1 AS n1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL
          SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL 
          SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 
        ) AS t1 CROSS JOIN (
          SELECT 1 AS n2 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL 
          SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL 
          SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
        ) AS t2
      ) AS t CROSS JOIN (SELECT @rn := -1) AS var   
    ) AS tally ON DATEDIFF(date_to, date_from) >= rn
    ORDER BY `date`
    Ответ написан
    Комментировать