工作中遇到的SQL

1.根据a表中的字段col,修改b表中的col

UPDATE a INNER JOIN b ON a.id = b.id SET b.col = xx WHERE a.col = xx

2.模糊查询 like 的替换为FIND_IN_SET

SELECT*FROM sku aLEFT JOIN classroom b ON a.targetId = b.idWHERE FIND_IN_SET(59, REPLACE(a.sn, ‘|‘, ‘,‘))AND a.targetType = "classroom"AND b.recommended = 1AND b.`status` = ‘published‘GROUP BY a.targetIdORDER BY b.recommendedSeq DESC, b.recommendedTime DESC;

相关文章