Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Question

Posted on 2016-08-04
1
Medium Priority
?
53 Views
Last Modified: 2016-08-04
I'm trying to figure out this query for SQL Server

My table has records that are inserted as follows

note      process               start              stop
note1      myprocess       8/4/2016      
note1      myprocess                            8/5/2016


I want to group the two records on Note and Process and return a date difference between Start and Stop

Returned

Note               Process            DateTimeDiff
note1              myprocess      1


help?
0
Comment
Question by:keschuster
1 Comment
 
LVL 36

Accepted Solution

by:
ste5an earned 2000 total points
ID: 41743439
Rows, not records. Any chance to change your data loading?

Otherwise it is a simple GROUP BY:

SELECT  Note, 
        Process, 
        Min(Start), 
        Max(Stop), 
        DATEDIFF(DAY,Min(Start), Max(Stop))
FROM yourTable
GROUP BY Note, Process;

Open in new window

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

972 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