简体   繁体   English

我可以在同一个 SQL 查询中使用 LOWER 和 MIN 吗?

[英]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.

相关问题 BigQuery SQL - 我怎么知道最小值、最大值和平均值? - BigQuery SQL - how can i know the min, max and avg? SQL 查询 - 取这个 boolean 表达式的 MIN 是什么意思? - SQL query - What does taking the MIN of this boolean expression mean? 我可以在 Google Cloud SQL 中创建只读用户吗 - Can I create a read-only user in Google Cloud SQL BigQuery SQL 查询以指示共享相同值的 3 行序列 - BigQuery SQL query to Indicate a sequence of 3 rows sharing the same value 如何实时从数组和firestore数据库中查询存储的用户ID? - How can i query stored user ids from array in the real time and firestore database? 云 SQL:我可以在导出时使用相同的无服务器实例并启用 --offload 选项吗 - Cloud SQL: Can I use the same serverless instance on export with --offload option enabled 如何加载以前登录的用户? - How can I load the previous signed in user? 如何查询特定数据? - HOW CAN I QUERY A SPECIFIC DATA? 在 BigQuery 中使用 HyperLogLog 函数是否可以从对相同数据的相同查询中得到不同的结果? - Using HyperLogLog functions in BigQuery can you get different results from the same query on the same data? SQL 查询查找同一天安装和卸载应用程序的用户 - SQL Query to find users that install and uninstall an App on the same day
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM