sql语句中 and concat(bu.`name`,bu.real_name,bu.phone) like "%1%" 后边还可以在写concat() like "%1%" 条件吗
时间: 2024-03-29 14:40:08 浏览: 63
可以继续在后面写 `concat()` 函数并且使用 `like` 进行条件筛选,例如:
```
select * from table_name where concat(bu.`name`,bu.real_name,bu.phone) like "%1%" and concat(bu.`address`,bu.email) like "%2%"
```
这条 SQL 语句会筛选出 `table_name` 表中 `bu.name`、`bu.real_name` 和 `bu.phone` 字段中包含 "1",`bu.address` 和 `bu.email` 字段中包含 "2" 的记录。
相关问题
SELECT * FROM ( SELECT DECIDE_LEVEL_CD AS serv_grade_cd, DECIDE_LEVEL_NAME AS serv_grade_name FROM adb.BU_SE_BUYINVOICE_MAS WHERE ( (DECIDE_LEVEL_CD != '') OR (DECIDE_LEVEL_CD IS NOT NULL) ) AND ORG_CD LIKE concat('35', '%') AND BU_YEAR = ( SELECT BUSI_YEAR FROM adb.DC_PROC_BUSI_YEAR A WHERE PROC_NAME = 'P_BU_INV_ID' ) GROUP BY DECIDE_LEVEL_CD, DECIDE_LEVEL_NAME UNION SELECT DECIDE_LEVEL_CD AS CD, DECIDE_LEVEL_NAME AS NAME FROM adb.BU_SE_BUYINVOICE_DETL WHERE ( (DECIDE_LEVEL_CD != '') OR (DECIDE_LEVEL_CD IS NOT NULL) ) AND ORG_CD LIKE concat('35', '%') AND BU_YEAR = ( SELECT BUSI_YEAR FROM adb.DC_PROC_BUSI_YEAR A WHERE PROC_NAME = 'P_BU_INV_ID' ) GROUP BY DECIDE_LEVEL_CD, DECIDE_LEVEL_NAME ) aaa ORDER BY serv_grade_cd
这是一个 SQL 查询语句,目的是从两个数据表中检索出符合条件的数据,并按照 serv_grade_cd 进行排序。其中,第一个子查询从 BU_SE_BUYINVOICE_MAS 表中查询 serv_grade_cd 和 serv_grade_name,第二个子查询从 BU_SE_BUYINVOICE_DETL 表中查询 CD 和 NAME,两个子查询使用 UNION 进行合并。这个查询语句的条件是 DECIDE_LEVEL_CD 不为空或不为 '',ORG_CD 以 '35' 开头,BU_YEAR 等于一个子查询中查询出的 BUSI_YEAR。
阅读全文