SQL 按“喜欢”分组
我有一个疑问,我在哪里生成每月的客户联系活动。我们有几个类别(电子邮件发出、电子邮件输入、电话拨入、电话拨出等),有 8 种不同的“类型”结果。我需要有两组 - 一组用于所有“电子邮件”,一组用于所有“电话”。目前,我有一个 WHERE TYPE LIKE '%Email%' 和 TYPE LIKE '%Call%'。但是,我无法按这两个“LIKE”语句进行分组。有谁知道我怎样才能最好地实现这一目标?
我将查询简化为以下示例:
SELECT TYPE
FROM dbo.HISTORY
WHERE (TYPE LIKE '%email%') OR
(TYPE LIKE '%call%')
I have a query where I generate our monthly customer contact activity. We have several categories (email out, email in, phone call in, phone call out, etc.) There are 8 distinct "type" results. I need to have two groups-one for all "email" and one for all "phone". Currently, I have a WHERE TYPE LIKE '%Email%'and TYPE LIKE '%Call%'. However, I am not able to group by these two "LIKE" statements. Does anyone know how I can best achieve this?
I simplified the query down to this for the example:
SELECT TYPE
FROM dbo.HISTORY
WHERE (TYPE LIKE '%email%') OR
(TYPE LIKE '%call%')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可行:
尽管如此,我的建议是有一个类型代码表,其中包含另一列,用于说明每种类型是否被视为电子邮件或电话。这样您就不会依赖于遵循特定格式的类型名称,而这种格式肯定会在以后被遗忘。然后您可以轻松地对此进行分组:
This should work:
Although, my advice would be to have a type code table with another column that tells whether each type is considered an email or call. Then you're not reliant on the type name following a specific format which is sure to be forgotten down the road. You can then easily group on that:
将过滤语句放在where子句中不是更好吗?
Wouldn't it be better to put the filter statement into the where clause?