我有以下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)
答案 0 :(得分:2)
最简单的方法是使用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);