hey , wondering if there is a way to get first row...
# general
c
hey , wondering if there is a way to get first row of a group after group by?
m
First based on what criteria?
order by xxx limit 1
?
c
select brand_id, first(brand_name), first(brand_logo) from ofo_store_channel where REGEXP_LIKE(brand_name, ‘肯德基.*’) and partition_timestamp_second = 1659225600 and city=‘shanghai’ and country=‘CHN’ group by brand_id limit 10
how can i get first(brand_name), first(brand_logoal). one brand_id could have mulple brand_name and brand_logo
maybe not specific first row ,random row in the group is ok.
m
just limit 1 will return 1 row?
c
but there’re multiple brand_id.
what i want to do is first group by brand_id, and then get random row in each group
m
So you mean one for each brand_id?
c
yup
in trino, i can just use a window function.
something like
Copy code
rank() OVER (PARTITION BY clerk
                    ORDER BY totalprice DESC) AS rnk
not sure if it is possible in pinot
m
Yeah I don’t think this is possible using v1 engine today. cc: @Rong R for v2 engine
c
seems can use
FIRSTWITHTIME
all good
m
For my understanding, how will the query look like?
c
Copy code
select brand_id, FIRSTWITHTIME(brand_logo_url, partition_timestamp_second, 'STRING')
from ofo_store_channel 
where REGEXP_LIKE(brand_name, '肯德基.*') and partition_day = '2022-07-31' and city='shanghai'
group by brand_id
limit 10
not sure if it is recommended?
m
Yes, that should work