[英]How to use LIKE operator in DB2 with values from another table?
I have the following SQL query 我有以下SQL查询
SELECT
CASE
WHEN TYPES LIKE '%Linux%' THEN 'LINUX'
WHEN TYPES LIKE '%Windows%' THEN 'WINDOWS'
ELSE 'UNKNOWN'
END AS COMP,
COUNT(*) AS TOTAL
FROM
COMPUTERS.OS
GROUP BY
CASE
WHEN TYPES LIKE '%Linux%' THEN 'LINUX'
WHEN TYPES LIKE '%Windows%' THEN 'WINDOWS'
ELSE 'UNKNOWN'
END
It works flawlessly, but I need to take values (Linux, Windows) to fill LIKE...THEN statement from another table? 它可以完美地工作,但是我需要取值(Linux,Windows)来填充另一个表中的LIKE ... THEN语句? How can I achieve this?
我该如何实现?
Thank you! 谢谢!
You can use a join
: 您可以使用
join
:
SELECT ot.comp, COUNT(*) AS TOTAL
FROM COMPUTERS.OS JOIN
OtherTable ot
ON types like ot.pattern
GROUP BY ot.comp;
This assumes that othertable
has two columns, one is the pattern and the other is comp
. 假设
othertable
有两列,一列是模式,另一列是comp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.