Slackbot
12/28/2022, 11:18 AMJohn Kowtko
12/28/2022, 7:31 PMWith tmp as (
select case when TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata') < TIME_FORMAT(CURRENT_TIMESTAMP,NULL,'Asia/Kolkata')
then TIME_FORMAT((TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata')),'yyyy-MM-dd','Asia/Kolkata')
else 'null' end) as a1,
Machine_count
From metadata
)
select a1, sum(Machine_count)
From tmp
group by a1
If that does not work, and/or your initial query is not producing the correct result, then please explain a bit more what you are trying to do ... and also provide a count(*) and count(distinct Machine_Date) for the table.
Thanks. JohnJohn Kowtko
12/28/2022, 10:24 PMWith tmp as (
select case when TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata') < TIME_FORMAT(CURRENT_TIMESTAMP,NULL,'Asia/Kolkata')
then TIME_FORMAT((TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata')),'yyyy-MM-dd','Asia/Kolkata')
else 'null' end) as a1,
Machine_count
From metadata
)
select sum(Machine_count), a1
From tmp
group by 2
you could also write the CTE as an inline table:
select sum(Machine_count), a1
From (
select case when TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata') < TIME_FORMAT(CURRENT_TIMESTAMP,NULL,'Asia/Kolkata')
then TIME_FORMAT((TIME_PARSE("Machine_Date", NULL, 'Asia/Kolkata')),'yyyy-MM-dd','Asia/Kolkata')
else 'null' end) as a1,
Machine_count
From metadata
)
group by 2
not sure if any of this will work with whatever SQL syntax restrictions you are working with ...John Kowtko
12/29/2022, 12:35 AMVadim
12/29/2022, 7:05 AM2 with the full case expression it works. Not sure what is up. This is a bug as far as I can see (probably in calcite with how it handles the 2 shortcut)Vadim
01/03/2023, 10:43 PMRahul Sharma
01/06/2023, 6:23 AM