在SQL中区分大小写的情况下统计每行中属性值的出现

问题描述

我有表格( notes_subject )结构-

+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id           | int         | NO   | PRI | NULL    | auto_increment |
| user_id      | int         | NO   |     | NULL    |                |
| note_id      | varchar(25) | NO   | MUL | NULL    |                |
| subject_name | text        | NO   |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+

和存储在此表中的数据-

+----+---------+--------------+--------------+
| id | user_id | note_id      | subject_name |
+----+---------+--------------+--------------+
| 10 |       2 | UdMs870BSswp | CN           |
| 12 |       2 | 8stMvslwIGr2 | CN           |
| 13 |       2 | PB3KNbbFkaUm | cn           |
+----+---------+--------------+--------------+

注意:CN和cn(小写)不同。

我想通过此表中的subject_name计算每个user_id的出现。所以我运行查询-

SELECT subject_name,COUNT(subject_name) 
FROM notes_subject where user_id=2 GROUP BY subject_name;

它获取了-

+--------------+---------------------+
| subject_name | COUNT(subject_name) |
+--------------+---------------------+
| CN           |                   3 |
+--------------+---------------------+

但这不是正确的结果,因为CN和cn不同。
而且我还希望结果中包含id,user_id,note_id。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)