two sub query in sql

64 Views Asked by At

I am working on an application in which I have to retrieve min and max date from DATETIME Column and then set min and max value to JSlider.

My Date format present in database : 2017-06-22T03:16:26Z

But I only want date in two formats 20170622031626 AND 20170622

I have tried some sql query but doesn't get the required results.

Here are two query I am using :

SELECT DISTINCT( REPLACE("DATETIME",'-','') ) FROM CDR WHERE DATETIME = (SELECT MIN(DATETIME) FROM CDR)

OUTPUT: 20170501T00:00:00Z

select min(replace(replace(replace(replace("DATETIME",'-',''),'T',''),'Z',''),':','')) FROM CDR

OUTPUT: 20170501000000

The second query gives the one of the required results but how can I get only 20170501 ?

Any idea how can I achieve the required results ??

0

There are 0 best solutions below