Unable to use time series or get date function for a trend graph

Hi,

I am using a Postgres DB to fetch detail to Grafana. While using Postgres DB we are unable to form any trend graphs.
For ex :
Direct DB query :
select to_timestamp(auditTime / 1000)::date as date, count(distinct (username))
from audit_log
where eventtype = 1
group by to_timestamp(auditTime / 1000)::date;

Grafana time series format:
select count as “Active Sessions”, time from (
select to_timestamp(auditTime / 1000)::date as date, count(distinct (username))
from audit_log
where eventtype = 1
group by to_timestamp(auditTime / 1000)::date;)
as sub order by time desc

Error: pq: column “time” does not exist

Please help me to fix this.

Regards,
Ipsita Dash