sql - 在 SQL 中使用带大小写的 IN 运算符?
问题描述
我正在尝试运行与IN
运算符一起使用的 case when 语句 - 这样,当URL
向 IN 子句提供值(或值)时,当它们匹配时,它会在给值 1 或 Null 时执行这种情况提供的 URL 或一组 URL。
我比较纠结于如何在IN
操作时实际使用操作符。我希望能够在具有 url 的地方提供多个值 - 而不是一个。这可能吗?
我的代码如下:
create temp table ag_table as
with sq AS(select id, business,
cat1, cat2, channel, call_reason,
COUNT(case cat1 when url then 1 else null end)
over (partition by subject
order by
time range between 604800 preceding
and current row) as count
from table_name
where table_name.start >= start and table.end_time <= end
)
注意我正在使用 SQLite
解决方案
这是 CASE 表达式的语法:
COUNT(case when category1 IN (url1, url2, ...) then 1 end)
不需要else null
(null 是没有 else 时的默认值)。
同样可以通过以下方式实现:
SUM(category1 IN (url1, url2, ...))
推荐阅读
- sql - 如何在 TimescaleDB 中的一张表上创建多个连续聚合?
- javascript - 正则表达式电话号码验证,带有空格和最小数字的字符
- javascript - ngtemplateoutlet 在两个不同的循环中
- regex - 如何使用正则表达式提取化学术语
- php - 使用代理和通过代理建立隧道有什么区别
- php - 如何不缓存动态路由
- python - 在 XML 和 Python 中处理属性条件
- c# - 将两个列表与一个列表作为用户输入进行比较总是触发标志
- java - 从java中的n个字符串用户输入中提取单词
- javascript - jQuery 视频播放器的全屏切换未正确分配类名