I have huge data in hive table. PFB sample rows.
Table:
Clid,pid,lid
1 ,1 ,OJA
1 ,2 , KLM
1, 2 , MHK
1 ,2, DNY
I want to write impala query to get count of lid for each clid,pid group along with sample value. I know how to get count but how can I get sample value of lid for each clid, pid group.
Select clid, pid, count(lid) frim t group by clid,pid
What should I add in impala query to get sample lid as shown in below result.
Expected result:
Clid, pid, count, sample lid
1, 1, 1, OJA
1, 2,3,MHK
I have tried using first_val function with over clause but it's giving error.
select clid,pid, count (lid), first_value(lid) over (partition by clid, pid) from t group by clid, pid
Error:
AnalysisException: select list expression not produced by aggregation output (missing from GROUP BY clause?): first_value(lid) OVER (PARTITION BY clid,pid)