Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Question

Posted on 2016-08-04
1
Medium Priority
?
49 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
[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
1 Comment
 
LVL 35

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…

722 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