Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Retrieving data per time interval help

$
0
0
HiI have a database table that records pH values from once per second.I want to retrieve the data per minute and group the data so that I know how many minutes per pH value over the course of the last 24 hours.I Tried using the following codeSelect DateAdd(minute, DateDiff(minute, 0, DateTime), 0) AS [DAY_MINUTE], Count(*) AS [TOTAL_MINUTE], TagName, Round(Value, 2) as pHFrom INSQL.Runtime.dbo.History Where TagName = 'AT7075.PV'Group By DateAdd(minute, DateDiff(minute, 0, DateTime), 0), TagName, Valueorder by DateAdd(minute, DateDiff(minute, 0, DateTime), 0) descbut it only gives me the data for the last hour, and the pH values aren't grouped as I hoped.example of retrieved dataDAY_MINUTE2016-02-17 08:37:00.000 1 AT7075.PV 7.012016-02-17 08:37:00.000 2 AT7075.PV 7.012016-02-17 08:37:00.000 1 AT7075.PV 7.042016-02-17 08:37:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.022016-02-17 08:36:00.000 1 AT7075.PV 7.022016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.042016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 2 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 2 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 1 AT7075.PV 7.052016-02-17 08:36:00.000 5 AT7075.PV 7.05

Viewing all articles
Browse latest Browse all 3145

Latest Images

Trending Articles



Latest Images