一:mybatis进行distinct进行查询的时候,数据库中可能有值为null的. 如果直接这样写,这个null的都给计算出来了. select DISTINCT b.b_city from buildinfo b 所以由于知识的有限,现在这样写,会把null的给进行处理掉 SELECT b.b_city, count(DISTINCT b.b_city) distinctcity from buildinfo b GROUP BY b.b_city HAVING distinctcity >
step1:构造连接Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db","root","123"); step2:构造语句String sql = "select username,password from t_user where
原文:https://www.2cto.com/database/201612/580140.html 1)数据库设计方面: a. 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. b. 应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is null 可以在num上设置默认值0,确保表中num列没有null值,然后这样查询: