我在sql server 2016中执行以下代码时遇到问题
select SUBSTRING ('email', CHARINDEX ('@', 'email') + 1, LEN ('email')-CHARINDEX ('@', 'email'))
count (email)
from income
它的说法期待'('或选择在最后一行的电子邮件附近。我也试过'电子邮件'
答案 0 :(得分:3)
在第一列选择后,您将错过逗号...这是您的SUBSTRING功能。我还添加了一个列名...然后需要该组。此外,您可能不希望电子邮件的实际文本的子字符串,而是列电子邮件,因此我删除了引号。
select
SUBSTRING (email, CHARINDEX ('@', email) + 1, LEN (email)-CHARINDEX ('@', email)) as DerrivedColumn, --comma added here, removed quotes, aliased column
count(email) as EmailCount --added column alias
from income
group by
SUBSTRING ('email', CHARINDEX ('@', 'email') + 1, LEN ('email')-CHARINDEX ('@', 'email'))