TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
479
2.9k
197.9k
Group by Name and sum column radnisati and prekovremeni sati
Apr 30 2018 2:49 AM
Code from sql working fine
I need sum column radni sati and column prekovremeni sati
SUM (cast(radni_sati as float)) as Ukpuno_radni_sati
group by radnik...something like this...
SELECT a.IdPrijava, a.redni_broj , a.radnik, isnull(convert(varchar(20), a.vrijemeodjave, 113),
''
) as vrijemeodjave, convert(varchar(20), b.vrijemeprijave, 113) as vrijemeprijave,
CASE WHEN DATEPART(WEEKDAY, b.vrijemeprijave) in (1,7) then 0
else
(CASE WHEN (DATEDIFF(SECOND, b.vrijemeprijave, a.vrijemeodjave) / 3600) > 8 THEN 8 ELSE(DATEDIFF(SECOND, b.vrijemeprijave, a.vrijemeodjave) / 3600) END) end AS radni_sati,
CASE WHEN DATEPART(WEEKDAY, a.vrijemeodjave) in (1,7) then (DATEDIFF(SECOND, b.vrijemeprijave, a.vrijemeodjave) / 3600)
else
(
case
when(DATEDIFF(SECOND, b.vrijemeprijave, a.vrijemeodjave) / 3600) > 8 then ((DATEDIFF(SECOND, b.vrijemeprijave, a.vrijemeodjave) / 3600)-8) ELSE NULL END) end AS prekovremeni
FROM(SELECT IdPrijava, redni_broj, radnik, vrijemeodjave, ROW_Number() OVER(Partition By IdPrijava ORDER BY vrijemeprijave) as RowNum
FROM dbo.prijava_radnika) a INNER JOIN(SELECT IdPrijava, redni_broj, radnik, vrijemeprijave, (ROW_Number() OVER(Partition By IdPrijava ORDER BY vrijemeprijave) - 1) as RowNumMinusOne FROM dbo.prijava_radnika) b ON a.IdPrijava = b.IdPrijava where 1 = 1
Group by Name and sum column radnisati and prekovremeni sati
Reply
Answers (
5
)
References Key in SQL
clustered index and non clustered index in sql