简体   繁体   English

SQLite 使用 GROUP BY 而不区分大小写

[英]SQLite using GROUP BY without being case sensitive

I have got a column for Email adresses in my table, where it's possibile for the adresses to be all lower case, all upper case, camelcase, etc. How can I modify my query so, that adresses like example@gmail.com and EXAMPLE@GMAIL.COM will be grouped together.我的表格中有一个用于电子邮件地址的列,其中的地址可以全部为小写、全部大写、驼峰式等。我如何修改我的查询,例如 example@gmail.com 和EXAMPLE 之类的地址@GMAIL.COM 将被分组在一起。

Thats my actual query:那是我的实际查询:

SELECT count(Email) as Number, Email
FROM tbl_SAP_Users
GROUP BY Email
HAVING Number > 1
ORDER BY Number DESC;

You can group by lower(Email) :您可以group by lower(Email)

SELECT count(*) as Number, lower(Email) Email
FROM tbl_SAP_Users
GROUP BY lower(Email)
HAVING Number > 1
ORDER BY Number DESC;

Or use COLLATE NOCASE in the GROUP BY clause:或者在GROUP BY子句中使用COLLATE NOCASE

SELECT count(*) as Number, Email
FROM tbl_SAP_Users
GROUP BY Email COLLATE NOCASE
HAVING Number > 1
ORDER BY Number DESC;

You could try the LOWER() function to make them all lower case.您可以尝试使用LOWER()函数使它们全部小写。

You might also want to use TRIM() to address whitespace at either end.您可能还想使用TRIM()来解决两端的空白。

SELECT count(Email) as Number, Email
FROM tbl_SAP_Users
GROUP BY LOWER(TRIM(Email))
HAVING Number > 1
ORDER BY Number DESC;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM