简体   繁体   English

如何在DB2中将LIKE运算符与另一个表中的值一起使用?

[英]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.

相关问题 将 sql 表 (t1) 从一个 db (db1) 导入到另一个 (db2) (t2),然后使用 t2 更新 db2 中表的值 - Importing sql table (t1) from one db (db1)to another (db2) (t2)and then use t2 to update values of a table in db2 如何在 DB2 中将 LIKE 与 IN 一起使用? - How to use LIKE with IN in DB2? 用另一个表中的多个值替换列值 - DB2 - Replace a column value with multiple values from another table - DB2 我可以在“喜欢”或“包含”运算符/函数中使用表列名称作为db2中的搜索参数吗? - Can I use a table column name as a search argument in db2 “like” or “contain” operator/function 具有类似值的DB2高效选择查询,可用于许多值(〜200) - DB2 efficient select query with like operator for many values (~200) TOAD DB2 Like Operator - TOAD DB2 Like Operator 如何使用 IN 和 LIKE 运算符将值与 SQL 中另一个表中的多个值进行比较? - How to compare values with multiple values from another table in SQL using IN and LIKE operator? DB2 SQL-选择与另一个表相关的表的所有值 - DB2 SQL - Select all values of a table related to another table 在 SQL DB2 中,如何检查一个表中的值列表是否在另一个表中可用? - In SQL DB2, how would I check if a list of values in one table is available in another table? DB2 LIKE运算符的奇怪长度限制 - Strange length restriction with the DB2 LIKE operator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM