How to get daily count with date generate 2 - 2 days after in last 7 dates in sql server?

coderwill

I am create one query for the get daily last 7 dates email count in the sql server. and i am write one query but not given expected output the table. right now just give the count in last 7 dates. here below write my query and tell me where is my mistake.

This is my query =>

SELECT dateadd(day, T.i, CAST(GETDATE() AS DATE)) AS DateColumn, uf.TotalCount 
        FROM (VALUES (-6), (-5), (-4), (-3), (-2), (-1), (0)) AS T(i)
        OUTER APPLY 
        (
           SELECT Count(InsertDateTime) AS TotalCount
           FROM Email
           WHERE Datediff(day,InsertDateTime, dateadd(day, T.i, getdate())) = 0 
        ) uf

This is my o/p=>
    DateColumn | Count
    15-06-2017    10
    16-06-2017    05
    17-06-2017    20
    18-06-2017    10
    19-06-2017    30
    20-06-2017    50
    21-06-2017    40


This is my Expected output =>

DateColumn | Count
03-06-2017    10
06-06-2017    05
09-06-2017    20
12-06-2017    10
15-06-2017    30
18-06-2017    50
21-06-2017    40

any one know how can do that please tell me.

TriV

If you want the same Count value output then change it.

SELECT dateadd(day, T.i * 3, CAST(GETDATE() AS DATE)) AS DateColumn, uf.TotalCount 
        FROM (VALUES (-6), (-5), (-4), (-3), (-2), (-1), (0)) AS T(i)
        OUTER APPLY 
        (
           SELECT Count(InsertDateTime) AS TotalCount
           FROM Email
           WHERE Datediff(day,InsertDateTime, dateadd(day, T.i * 3, getdate())) = 0 
        ) uf

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to count fractional days between 2 dates

From Dev

How to get count data column in SQL server between different dates and each date has time range?

From Java

How to count the visits of the last 7 days in MySQL

From Dev

Count number of days between 2 dates in JPA

From Dev

Get the highest value of the last 7 days with SQL

From Dev

SQL - Get an average price of the last 7 days

From Dev

pandas count values for last 7 days from each date

From Dev

Rolling Running total over last 7 days by date and not bound by rows preceding but rather dates preceding for each row in a SQL Table

From Dev

SQL Output to get only last 7 days output while using convert on date

From Dev

How to get articles for last 2 days only in Python?

From Dev

C# - Get days between 2 dates

From Dev

How to get dates between a date range given a day in SQL Server

From Dev

Generate date range in between 2 dates

From Dev

How to get last 7 days record from table as per date using PHP and MySQL

From Dev

How to count daily sales of salesman and show dates as a column in SQL QUERY

From Dev

How to count daily sales of salesman and show dates as a column in SQL QUERY

From Dev

Split days between 2 given dates into specific batch size and get the start and end_date accordingly

From Dev

get last 7 days when user picks up a date

From Dev

JavaScript: How to get dates for seven days ago, last month, this week

From Dev

MYSQLI How to display and count date for the last 3 days

From Dev

How to count no. of days between 2 dates from calendar in string format vb

From Dev

How to get last date of month SQL Server 2008

From Dev

How to get count of 2nd and 4th Saturday's exactly between 2 dates using sql query

From Dev

How do I get count of weekend days from a range of dates

From Dev

Wrong count of difference days between 2 dates with joda time?

From Dev

How to count business days from a given date in SQL Server using a calendar reference table

From Dev

How to Determine consecutive date count/days in SQL Server "finding islands" (consecutive rows)

From Dev

How to get list of 2nd and 4th Saturday dates in SQL Server?

From Dev

Calculate how many days between 2 dates (one date may be blank) Google Spreadsheets

Related Related

  1. 1

    How to count fractional days between 2 dates

  2. 2

    How to get count data column in SQL server between different dates and each date has time range?

  3. 3

    How to count the visits of the last 7 days in MySQL

  4. 4

    Count number of days between 2 dates in JPA

  5. 5

    Get the highest value of the last 7 days with SQL

  6. 6

    SQL - Get an average price of the last 7 days

  7. 7

    pandas count values for last 7 days from each date

  8. 8

    Rolling Running total over last 7 days by date and not bound by rows preceding but rather dates preceding for each row in a SQL Table

  9. 9

    SQL Output to get only last 7 days output while using convert on date

  10. 10

    How to get articles for last 2 days only in Python?

  11. 11

    C# - Get days between 2 dates

  12. 12

    How to get dates between a date range given a day in SQL Server

  13. 13

    Generate date range in between 2 dates

  14. 14

    How to get last 7 days record from table as per date using PHP and MySQL

  15. 15

    How to count daily sales of salesman and show dates as a column in SQL QUERY

  16. 16

    How to count daily sales of salesman and show dates as a column in SQL QUERY

  17. 17

    Split days between 2 given dates into specific batch size and get the start and end_date accordingly

  18. 18

    get last 7 days when user picks up a date

  19. 19

    JavaScript: How to get dates for seven days ago, last month, this week

  20. 20

    MYSQLI How to display and count date for the last 3 days

  21. 21

    How to count no. of days between 2 dates from calendar in string format vb

  22. 22

    How to get last date of month SQL Server 2008

  23. 23

    How to get count of 2nd and 4th Saturday's exactly between 2 dates using sql query

  24. 24

    How do I get count of weekend days from a range of dates

  25. 25

    Wrong count of difference days between 2 dates with joda time?

  26. 26

    How to count business days from a given date in SQL Server using a calendar reference table

  27. 27

    How to Determine consecutive date count/days in SQL Server "finding islands" (consecutive rows)

  28. 28

    How to get list of 2nd and 4th Saturday dates in SQL Server?

  29. 29

    Calculate how many days between 2 dates (one date may be blank) Google Spreadsheets

HotTag

Archive