最近遇到段代码,在其他数据库比如sql server、kudu执行时会报错,但在mysql执行没问题
select customer_id, type, value from ${tableName} where tenant_id = :tenantId and
customer_id in (:customerIds) and type in (identityTypes) group by customer_id, type
一般来说查询的字段要和group by的字段一致,但是mysql做了特殊处理
实际上执行的是
select customer_id, type, any_value(value) from customer_identity where tenant_id = 10023
and customer_id in (989633593863100416) and type in ("c_dmhub_userid") group by customer_id, type
any_value()会选择被分到同一组的数据里第一条数据的指定列值作为返回数据