我有以下MySQL
查询结果,我只想要@
之前的UserName第一部分,它只需要10000013
部分,我想删除example.com
部分,可以通过TRIM吗?
mysql> SELECT UserName,DAY(AcctStartTime), COUNT(ResponseCode='200') FROM table201412 WHERE UserName='10000013@example.com' GROUP BY DATE(AcctStartTime);
+---------------------------+--------------------+------------------------------+
| UserName | DAY(AcctStartTime) | COUNT(ResponseCode='200') |
+---------------------------+--------------------+------------------------------+
| 10000013@example.com | 1 | 3 |
| 10000013@example.com | 2 | 5 |
| 10000013@example.com | 3 | 3 |
+----------------------+--------------------+------------------------------+
10 rows in set (0.00 sec)
我需要以下结果:
+---------------------------+--------------------+------------------------------+
| UserName | DAY(AcctStartTime) | COUNT(ResponseCode='200') |
+---------------------------+--------------------+------------------------------+
| 10000013 | 1 | 3 |
| 10000013 | 2 | 5 |
| 10000013 | 3 | 3 |
+---------------------------+--------------------+------------------------------+
10 rows in set (0.00 sec)
最佳答案
最简单的方法是使用substring_index()
:
select substring_index(UserName, '@', 1) as EmailName
在您的查询中,这将是:
SELECT substring_index(UserName, '@', 1) as EmailName, DAY(AcctStartTime), COUNT(ResponseCode='200')
FROM table201412
WHERE UserName='10000013@example.com'
GROUP BY DATE(AcctStartTime);
关于MySQL TRIM SELECT 结果输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27448045/