ADS_ADVERTISEMENT_EXPOSURE adeON ad.ADVERTISEMENT_ID=ade.ADVERTISEMENT_IDWHEREad.ADVERTISEMENT_ID=#{advertisementId}<if test="list != null ">and ade.CREATED_DATE LIKE concat(#{list[0]},'%')<foreach item="item" collection="list" open="" close="" index="1">or ade.CREATED_DATE LIKE concat(#{item},'%')</foreach></if>GROUP BYcreateTime//group by是根据别名来分组的。
mysql查询最后一条插入的ID:
适用int类型:
SELECT LAST_INSERT_ID() ;
SELECT MAX(id) FROM table
String sql = "INSERT INTO users (username,password,email) VALUES (?,?,?);"; PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);//传入参数:Statement.RETURN_GENERATED_KEYS
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.setString(3, user.getEmail());
pstmt.executeUpdate();//执行sql int autoInckey = -1;
ResultSet rs = pstmt.getGeneratedKeys(); //获取结果
if (rs.next()) {
autoIncKey = rs.getInt(1);//取得ID
} else {
// throw an exception from here
}
-