Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6139475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:59:40+00:00 2026-05-23T17:59:40+00:00

i have the following table Log Date date Description varchar ID integer Given a

  • 0

i have the following table

   Log

 Date            date
 Description     varchar
 ID              integer

Given a date as a parameter,i have to find the no. or count of logs logged each day from start date to a month after it using recursive cte.
Some Days may have not any logs,so i have to print the count as 0.

ex:

  select * from Log

returns

  1   insert      2011-01-17
  2   blah blah   2011-01-23
  3   blah        2011-07-07

For 2011-01-17 as input,the output should be

   2011-01-17    1
   2011-01-18    0
   2011-01-19    0
   ....
   2011-01-23    1
   .....
   2011-02-17    0

I have to use recursive cte to do that.i don’t know how to increment the date by 1 in each recursion and how to stop\terminate the recursion.

This is the thing i have done so far:

 with cte as    (
    select '2011-01-17' as dat,count(*) as count 
from log group by date 
having date='2011-01-17' 

union all 

select dateadd(day,1,dat) as dat,count(*) as count 
from log,cte 
group by date 
having date=dateadd(day,1,dat) 
where dat<'2011-02-17' 
) 
select * from cte
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:59:40+00:00Added an answer on May 23, 2026 at 5:59 pm
    WITH    days (d, maxd) AS
            (
            SELECT  MIN(date), MAX(date)
            FROM    log
            UNION ALL
            SELECT  DATEADD(day, 1, d), maxd
            FROM    days
            WHERE   d < maxd
            )
    SELECT  d, COUNT(id)
    FROM    days
    LEFT JOIN
            log l
    ON      l.date = d
    GROUP BY
            d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a log table with the following format (and sample data): date |
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
I have following query in PostgreSQL: SELECT COUNT(a.log_id) AS overall_count FROM Log as a,
I have the following table: log(productId, status, statusDate, department...) , where productId, status and
I have a transaction log table that is updated each time a record is
I have a SQL Server table with the following structure: CREATE TABLE [dbo].[Log]( [LogID]
I have the following table EVENT_LOG : EVENT_ID: pk, int, not null TYPEID: fk,
Say I have a 'user_log' table with the following field: id user_id status_text timestamp
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table relationship in my database: Parent / \ Child1 Child2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.