SQL | How to generate missing date records | How to create Reports showing data for each day

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ค. 2024
  • In this video, we write a SQL query to generate missing date records.
    Example in the video -
    Generate a report showing order count for each day including days when no orders were placed.
    How to install SQL Server for practice?
    • How to install SQL Ser...
    Check out the complete list of SQL Query Interview Questions -
    • SQL Query Interview Qu...
    Best Data Science / Analytics / SQL courses
    Learn SQL Basics for Data Science Specialization
    imp.i384100.net/qnXYk5
    Beginners to Python Programming
    skillshare.eqcm.net/GjMakm
    Data Science and Business Analytics with Python
    skillshare.eqcm.net/JrM1Aq
    Get 40% OFF of Skillshare with code FLASH40 - October 2022
    skillshare.eqcm.net/c/3299742...
    Data Science Fundamentals with Python and SQL Specialization
    imp.i384100.net/mgVYre
    Python for Everybody Specialization
    imp.i384100.net/DVz7Aj
    Google Data Analytics Professional Certificate
    imp.i384100.net/OR37oQ
    Coursera Plus - Data Science Career Skills
    imp.i384100.net/c/3299742/132...
    Please do not forget to like, subscribe and share.
    For enrolling and enquiries, please contact us at
    Website - knowstar.org/
    Facebook - / knowstartrainings
    Linkedin - www.linkedin.com/company/know...
    Email - learn@knowstar.org

ความคิดเห็น • 46

  • @SP-fc9bx
    @SP-fc9bx 2 ปีที่แล้ว +2

    You are so awesome! SQL came late for me in life but learning all these cool tricks is helping a LOT

  • @agape13
    @agape13 2 ปีที่แล้ว +3

    Queen 👑 !
    Excellent channel and teaching skills 🏆

  • @shaikhkalim956
    @shaikhkalim956 ปีที่แล้ว

    Every helpful video, nice way of explanation 👍

  • @sravankumar1767
    @sravankumar1767 2 ปีที่แล้ว

    Superb explanation 👌 👏

  • @kingstonxavier
    @kingstonxavier 2 ปีที่แล้ว +1

    We can apply having clause count(OrderID) is Null to filter out the missing dates

  • @briandennehy6380
    @briandennehy6380 2 ปีที่แล้ว

    Super stuff

  • @ramyagopinath8320
    @ramyagopinath8320 ปีที่แล้ว

    Awesome content❤

  • @sureshsugoor
    @sureshsugoor ปีที่แล้ว

    Nice explained 💐

  • @subhadarshisethy1680
    @subhadarshisethy1680 2 ปีที่แล้ว +1

    Ty mam...

  • @aadarshchaudhari3957
    @aadarshchaudhari3957 10 หลายเดือนก่อน

    Thanks

  • @robertmaslo1348
    @robertmaslo1348 2 ปีที่แล้ว

    Sequence generation is very easy in MySQL: SELECT seq FROM seq_1_to_31

  • @bobgamble8204
    @bobgamble8204 2 ปีที่แล้ว +2

    A CTE is not the same as a temporary table. It just isn't.

  • @pratz17
    @pratz17 ปีที่แล้ว

    nice approach. I have another doubt:
    How to use/fill the record for missing dates from the previous dates ?
    like 10th January is the missing date then how can we make use of values on 9th jan and copy for 10th jan and generate a new table with all the dates ?

    • @LearnatKnowstar
      @LearnatKnowstar  ปีที่แล้ว

      Thank you for your comment. The forward fill approach is the topic for our next video coming this week. Stay tuned and please Subscribe 🙏

    • @localmartian9047
      @localmartian9047 ปีที่แล้ว

      We can use lag window function

  • @muizvasaya8435
    @muizvasaya8435 ปีที่แล้ว

    Thanks for the video, but I have a small problem when I'm creating dates month wise, its not resulting proper, its adding 30 days to each date, and with this it results this way
    2016-12-31 00:00:00.000
    2017-01-31 00:00:00.000
    2017-02-28 00:00:00.000
    2017-03-28 00:00:00.000
    Declare @startdate date='2016-12-31';
    Declare @endate date ='2022-7-31';
    With dates as
    (
    select @startdate as transactiondate
    union all
    Select dateadd(mm,1,transactiondate)
    from dates
    where dateadd(mm,1,transactiondate)

    • @ankitdeswal2231
      @ankitdeswal2231 ปีที่แล้ว

      This is because you're using month (mm) in the datepart for DATEADD fn this will increment the month by the number to add specified.
      Use dateadd(dd,1, transactiondate) and it will solve your problem.

  • @udayreddy7173
    @udayreddy7173 2 ปีที่แล้ว

    Hi, Please explain to create temp table with first 12 days in each month of a year

    • @judelaw12
      @judelaw12 3 หลายเดือนก่อน

      Don't, simply create a dates table, every DB should have a dates tables created.
      Just link to that table. Get a script online and select first 12 days for each month from that table.

  • @Niteshkumar-ly2ip
    @Niteshkumar-ly2ip ปีที่แล้ว

    Can you please share the scripts of this example?

  • @user-fi8iy6lh5z
    @user-fi8iy6lh5z ปีที่แล้ว

    How to find duplicate data without using Group by clause

  • @Ready_Set_Boom
    @Ready_Set_Boom 2 ปีที่แล้ว

    Where was this video 3 months ago. I came to a similar solution but I was struggling as a newbie.

  • @whyapparel5438
    @whyapparel5438 ปีที่แล้ว

    it is doesn't work in MySQL.

  • @nikolaybaranov2213
    @nikolaybaranov2213 2 ปีที่แล้ว +1

    Maximum recursion = 100, a longer sequence can't be generated.

    • @nikolaybaranov2213
      @nikolaybaranov2213 2 ปีที่แล้ว

      The value can be changed by specifying MAXRECURSION: SELECT OrderDate from Dates OPTION (MAXRECURSION NNN);
      MAXRECURSION >= 0 and

  • @adityaraopandrapagada1894
    @adityaraopandrapagada1894 2 ปีที่แล้ว +2

    Great Solution... I have a requirement: I have a cities column with or without duplicates. I need count of cities start with each alphabet. If there is no city with any alphabet it should be shown as zero. Can you help me out @LearnAtKnowstar ?

    • @LearnatKnowstar
      @LearnatKnowstar  2 ปีที่แล้ว

      You can perform a count by extracting first letter of each city..ex - Left(Cityname,1)

    • @LearnatKnowstar
      @LearnatKnowstar  2 ปีที่แล้ว

      Create a CTE with the list of all alphabets A-Z and perform a left join with the CTE on the first alphabet of column city

    • @adityaraopandrapagada1894
      @adityaraopandrapagada1894 2 ปีที่แล้ว +1

      @@LearnatKnowstar I wrote a query for firstname in Person.Person table, please lemme know whether my approach is correct or not.
      With t1 as (select row_number() over(order by object_id) as Alp from sys.columns),
      t2 as (select char(((Alp-1)%26)+65) alpha from t1 where Alp

    • @LearnatKnowstar
      @LearnatKnowstar  2 ปีที่แล้ว

      Looks perfect! Only not sure why there is group by on firstname for t3. Other than that, this should be giving the correct results.

    • @LearnatKnowstar
      @LearnatKnowstar  2 ปีที่แล้ว +1

      Thanks for mentioning this scenario. This is an interesting idea for us to cover in our video tutorials!

  • @Faisal1504
    @Faisal1504 2 ปีที่แล้ว

    Thanks