如何在查询中添加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;
感谢您的任何意见
答案 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;