Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sql query grouping by time

Posted on 2014-03-06
2
Medium Priority
?
341 Views
Last Modified: 2014-03-08
Dtime                                    points
2014-02-01 08:00                   .3
2014-02-01 08:15                   .2
2014-02-02 08:00                   .6
2014-02-03 08:00                   .9
2014-02-02  08:15                  .85
2014-02-04  08:00                  .98

I want to group by the time and add the ones that are over .8 and divide by the total
so for above example it will be
8:00----2/4
8:15---1/2
0
Comment
Question by:Angela4eva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Expert Comment

by:DrewKjell
ID: 39910790
select DATEPART(hh, dtime) as hour, DATEPART(mm,dtime), SUM(CASE WHEN points >.8 then 1 else 0 end))/count('s')
from [table]
group by DATEPART(hh, dtime) as hour, DATEPART(mm,dtime)

Open in new window

0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 39911120
SELECT
    DATEADD(MINUTE, DATEDIFF(MINUTE, 0, Dtime) / 15 * 15, 0) AS DTime,
    SUM(CASE WHEN points > 0.8 THEN 1 ELSE 0 END) / COUNT(*) AS points
FROM ...
GROUP BY     DATEADD(MINUTE, DATEDIFF(MINUTE, 0, Dtime) / 15 * 15, 0)
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question