我是新手,psql
并且对计算每天唯一的首次用户的数量很感兴趣。
我的表只有两列 - user_id
(一个用户每天可以多次使用),start_time
这是指示使用时间的时间戳。计数应仅包括当天 min(start_time) 下降的用户。
为什么以下查询不起作用?难道不能一次在两个变量上选择不同的吗?
SELECT COUNT (DISTINCT min(start_time::date), user_id),
start_time::date as date
FROM mytable
GROUP BY date
Run Code Online (Sandbox Code Playgroud)
产生
错误:函数
count(date, integer)
不存在
输出看起来像这样
date count
1 2017-11-22 56
2 2017-11-23 73
3 2017-11-24 13
4 2017-11-25 91
5 2017-11-26 107
6 2017-11-27 33...
Run Code Online (Sandbox Code Playgroud)
关于如何计算不同的 min Date 和 user_id 然后在 psql 中按日期分组的任何建议将不胜感激。
我编写了一个简单的查询,它应该以人类可读的格式显示任何给定模式的所有表大小:
select table_name, pg_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'my_schema'
order by 2
Run Code Online (Sandbox Code Playgroud)
当我在 PgAdmin 中运行此查询时,出现以下错误:
ERROR: relation "my_table" does not exist
SQL state: 42P01
Run Code Online (Sandbox Code Playgroud)
这个错误怎么可能?我根本没有改变 information_schema ,如果关系首先不存在,为什么它会在 information_schema 中?知道这是怎么发生的吗?