Abhishek  Jaiswal

Abhishek Jaiswal

  • 90
  • 19.8k
  • 9.4m

SQL query

Aug 28 2014 8:59 AM
hello!

Problem: I want to select max and min date from the table for every row(GROUPING BY id) then perform date difference operation over it. Afterwards i want to divide that diff with 30 and store in another table. HOW TO DO THAT ?
eX TABLE

NameDateID
A5/3/141
B6/4/14 2
A5/4/141
C11/8/143
D6/7/144
C7/7/143
D9/9/144

my QUERY
SELECT INSERT INTO <TAB2>
SELECT DATEDIFF/30 AS DIFFFROM
(SELECT MAX(DATE),  MIN(DATE) FROM <TAB1>
GROUP BY ID) ;


but its not working pls suggest how to do date

Answers (5)