[英]Can I user LOWER and MIN in the same SQL query?
I am getting an issue with my query written, am I able to use a LOWER and a MIN In the same query?我在编写查询时遇到问题,我可以在同一个查询中使用 LOWER 和 MIN 吗?
SELECT DISTINCT
LOWER(id_5) AS "ID"
,MIN(visittime) AS "First Date"
FROM table
WHERE (date >= '2022-11-21')
AND (
server = 'pets.com' AND page = 'pets:dogs:puppy')
MIN
is aggregation function which can be used only with aggregation or as window function or scenarios reducible to this like in queries when only one row is expected: MIN
是聚合 function,它只能与聚合一起使用,或者作为window function或可以简化为这样的场景,比如在只需要一行的查询中:
select max(LOWER(id_5)) AS "ID" -- or any other aggregation function
, min(Status) AS "First Date"
from dataset;
which is equivalent to group by true
.这相当于group by true
。
Note that DISTINCT
works on all values in the select. If you want to find first visit per unique id_5
then just use group by
:请注意, DISTINCT
适用于 select 中的所有值。如果您想查找每个唯一id_5
的首次访问,则只需使用group by
:
SELECT LOWER(id_5) AS "ID"
, MIN(visittime) AS "First Date"
FROM table
WHERE (date >= '2022-11-21')
AND (
server = 'pets.com' AND page = 'pets:dogs:puppy')
group by LOWER(id_5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.