sql - How can I create a Date Range from a single column? -


i trying query database has these params:

transaction date, user email address 

the resultant table want these params:

email address, datediff 

for datediff, want find difference between earliest transaction date , latest transaction date.

how go doing this?

my code (clearly not correct)

select [email address], datediff(day, [transaction date],[transaction date]) 'datediff' [db].[table] order [datediff] desc 

you need aggregation minimum , maximum values each email, before doing datediff():

select [email address],        datediff(day, min([transaction date]), max([transaction date])) 'datediff' [db].[table] group [email address] order 2 desc; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -