Hours and minutes to calculate the average working time

Source: Internet
Author: User
-- Hours and minutes to calculate the average working time

Declare @ TB table ([date] varchar (3), [working hours] varchar (5 ))

Insert @ TB
Select '1', '3: 10' Union all
Select '2 ', '3: 20' Union all
Select '3', '4: 20' Union all
Select '4', '4: 30'

Select convert (varchar (5), dateadd (MI, AVG (datediff (MI, 0, working time), 0), 108) from @ TB

-- Mi minutes

/*
-----

 

-- Every hour of a day

Select convert (varchar (13), createtime, 120) [hour],
Count (*) CNT
From business_login
Where createtime> '2017-11-22'
Group
Convert (varchar (13), createtime, 120)
/*
2011-11-22 09 44
2011-11-22 10 48
2011-11-22 11 35
2011-11-22 12 34
2011-11-22 13 42
2011-11-22 14 33
2011-11-22 15 21
2011-11-22 16 45
2011-11-22 17 46
2011-11-22 18 6
*/

-- Press 0, 1, 2...
Select datepart (HH, createtime) [hour],
Count (*) CNT
From business_login
Where createtime> '2017-11-21'
Group
Datepart (HH, createtime)

/*
9 44
10 48
11 35
12 34
13 61
14 73
15 32
16 64
17 99
18 15
*/


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.