PostgreSQL如何添加WHERE在哪里是count()和GROUP

时间:2015-06-17 18:41:31

标签: sql postgresql

如何在查询中添加WHERE函数?

SELECT count(*), date_trunc('year', "createdAt") AS txn_year 
FROM tables
WHERE active = 1  // not working I don't know why 
GROUP BY txn_year;

感谢您的任何意见

2 个答案:

答案 0 :(得分:2)

SELECT count(*), date_trunc('year', "createdAt") AS txn_year 
FROM tables 
WHERE column_active = 1
GROUP BY txn_year;

答案 1 :(得分:1)

active的类型为character varying,即字符串类型。这应该有效:

SELECT count(*), date_trunc('year', "createdAt") AS txn_year 
FROM tables
WHERE active = '1'
GROUP BY txn_year;