Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含三列的用户表-> user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,用户名 VARCHAR(256),电子邮件 VARCHAR(100),国家/地区 VARCHAR(50)。
我运行这个查询 -> SELECT COUNT(*) FROM users WHERE country = 'Brazil'。
SELECT COUNT(*) FROM users WHERE country = 'Brazil'
这让我得到了来自巴西的用户总数。但我也想了解返回的行中是否存在特定的 user_id。
怎么做?
SELECT COUNT(*) AS cnt, SUM(IF(user_id=XXX, 1, 0)) AS xxx_is_present ...
如果 xxx 存在于基础结果集中,则总和将为> 0
> 0