I am creating a query in kibana>dev tools.
Some how my SQL query is not working due to group by function in console.
The SQL query is working fine in MSSQL management studio.
Query:
POST /_sql?format=txt&pretty
{
"query": """
Select loginyear,loginmonth,customerId,userId, count(1) customerwiseregularuser
from
(
SELECT customerId,userId,time,
DATETIME_FORMAT(CAST(time AS DATE), 'YYYY-MM-dd') AS "logindate",
DATETIME_FORMAT(CAST(time AS DATE), 'MM') AS "loginmonth" ,
DATETIME_FORMAT(CAST(time AS DATE), 'YYYY') AS "loginyear"
FROM "isco-regularusers" )a
GROUP BY loginyear,loginmonth,customerId,userId having count(1) >5
ORDER BY customerId,userId, customerwiseregularuser
"""
}
Try something like this and avoid nested SQL queries
POST /_sql?format=txt&pretty
{
"query": """
SELECT customerId,userId,
DATETIME_FORMAT(CAST(login_date AS DATE), 'YYYY-MM-dd') AS "logindate",
DATETIME_FORMAT(CAST(login_date AS DATE), 'MM') AS "loginmonth" ,
DATETIME_FORMAT(CAST(login_date AS DATE), 'YYYY') AS "loginyear",
count(*) as login_count
FROM "users-logon-data"
GROUP BY
DATETIME_FORMAT(CAST(login_date AS DATE), 'YYYY-MM-dd'),
DATETIME_FORMAT(CAST(login_date AS DATE), 'MM'),
DATETIME_FORMAT(CAST(login_date AS DATE), 'YYYY'),
customerId,userId having count(*) >= 1
order by customerId, userId
"""
}
The query i working, but i am not getting the desire the result what need.
I need the count of user who have login more then 5times in different days for the same month.
Requirement to create the query:
The number of regular users every month, regular users are those who have logged in on 5 different days in the same month (A user could log in several times on the same day, still would count as one).
For this we have the fields which was mentioned in the above query given in the use case.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.