Search
 
SCRIPT & CODE EXAMPLE
 

SQL

How to group by week (7 days) in SQL Server

SELECT
    CONVERT(VARCHAR(5), DATEADD(WK, WK, 0), 103) + ' - ' + CONVERT(VARCHAR(5), DATEADD(DD, 6, DATEADD(WK, WK, 0)), 103)
    , Cnt
FROM (
    SELECT
        DATEDIFF(WK, 0, MyDate) AS WK
        , COUNT(*) AS Cnt
    FROM (VALUES
    ('2013-01-01')
    , ('2013-01-02')
    , ('2013-01-03')
    , ('2013-01-04')
    , ('2013-01-05')
    , ('2013-01-06')
    , ('2013-01-07')
    ) AS X(MyDate)
    GROUP BY DATEDIFF(WK, 0, MyDate)
) AS X
Comment

PREVIOUS NEXT
Code Example
Sql :: flexible search query delete table 
Sql :: select-groups-of-row-only-having-specific-value 
Sql :: how to use mysql_tzinfo_to_sql on windows 
Sql :: what is a foriegn key 
Sql :: Failed to initialize, mariadb service is unhealthy. 
Sql :: how to create a table from another table in sql derby 
Sql :: oracle winter time change 
Sql :: postgres sum substract stackoverflow 
Sql :: oracle create job if not exists 
Sql :: mod function example 
Sql :: oracle synonym procedure dblink 
Sql :: mysql configuration file storage location 
Sql :: maximum number of tables in mysql 
Sql :: salesforce cpq apply immediately 
Sql :: how to reset id column in sql server 
Sql :: custom row number 
Sql :: sqlite ignore index 
Sql :: what to do if foreign key is making conflict while deleting record from sql table using c# 
Sql :: mysql drop table 
Sql :: sqlite 
Sql :: subquery in Insert 
Sql :: how to query a db sqlite3 database in django python 
Sql :: oracle sql first day of quarter 
Sql :: get id from just inserted row mysql server python 
Sql :: add column mssql 
Csharp :: count number of enum values C# 
Csharp :: Add component object to gameobject unity 
Csharp :: c# textboxaccept only numbers 
Csharp :: c# sleep 1 second 
Csharp :: c# check to see if dictionary key exists 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =