为什么sql 少了q_apkId=""的参数判断
for (PreinstallApk preinstallApk : preinstallApks) {
//cnd1 = Where.where(cnd1, "q_apkId", "=", preinstallApk.getId());// 通过软件id查询软件
sql.setVar("cnd", Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
// sql.setVar("cnd", Where.where(cnd1, "q_apkId", "=", preinstallApk.getId()));
System.err.println("=---"+ Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
}
for (Device devices : device) {
//cnd1 = Where.where(cnd1, "q_deviceId", "=", devices.getId());// 通过手机id查询软件
//sql.setVar("cnd", Where.where(cnd1, "q_deviceId", "=", devices.getId()));
sql.setVar("cnd", Cnd.NEW().and("q_deviceId", "=", devices.getId()));
System.err.println("=---"+Cnd.NEW().and("q_deviceId", "=", devices.getId()));
}
// Sql sql = Sqls.create("select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity $cnd )");
//sql.setVar("cnd", Cnd.NEW().andEX("t_activating_quantity.q_apkId", "=", "").andEX("t_activating_quantity.q_deviceId", "=", ""));
sql.setCallback(Sqls.callback.entities());
sql.setEntity(dao.getEntity(ActivatingQuantity.class));
Sql sql1= dao.execute(sql);
System.err.println("--------"+sql1.toString());
List<ActivatingQuantity> fetch = sql.getList(ActivatingQuantity.class);
System.err.println("--------"+fetch.toString());
日志
=--- WHERE q_apkId=1
=--- WHERE q_deviceId=112
--------select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity WHERE q_deviceId=112 )
--------[ActivatingQuantity [id=1379, apkId=39, deviceId=112, createtime=2017-11-28 09:16:56.0, time=4]]
18 回复
我的写法有点问题 问下有其他的写法
for (PreinstallApk preinstallApk : preinstallApks) {
//cnd1 = Where.where(cnd1, "q_apkId", "=", preinstallApk.getId());// 通过软件id查询软件
// sql.setVar("cnd", Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
sql.setVar("cnd", Where.where(cnd1, "q_apkId", "=", preinstallApk.getId()));
System.err.println("=---"+ Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
}
for (Device devices : device) {
//cnd1 = Where.where(cnd1, "q_deviceId", "=", devices.getId());// 通过手机id查询软件
sql.setVar("cnd", Where.where(cnd1, "q_deviceId", "=", devices.getId()));
// sql.setVar("cnd", Cnd.NEW().and("q_deviceId", "=", devices.getId()));
System.err.println("=---"+Cnd.NEW().and("q_deviceId", "=", devices.getId()));
}
日志如下
=--- WHERE q_apkId=1
=--- WHERE q_apkId=39
=--- WHERE q_deviceId=112
这样正确吗
Sql sql = Sqls.create("select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity $cnd )");
for (PreinstallApk preinstallApk : preinstallApks) {
//cnd1 = Where.where(cnd1, "q_apkId", "=", preinstallApk.getId());// 通过软件id查询软件
sql.setVar("cnd", Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
//sql.setVar("cnd", Where.where(cnd1, "q_apkId", "=", preinstallApk.getId()));
System.err.println("=---"+ Cnd.NEW().and("q_apkId", "=", preinstallApk.getId()));
}
for (Device devices : device) {
//cnd1 = Where.where(cnd1, "q_deviceId", "=", devices.getId());// 通过手机id查询软件
//sql.setVar("cnd", Where.where(cnd1, "q_deviceId", "=", devices.getId()));
Cnd.NEW().and("q_deviceId", "=", devices.getId());
System.err.println("=---"+Cnd.NEW().and("q_deviceId", "=", devices.getId()));
}
Sql sql = Sqls.create("select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity $cnd )");
Cnd cnd = Cnd.NEW();
for (PreinstallApk preinstallApk : preinstallApks) {
cnd.or(cnd1, "q_apkId", "=", preinstallApk.getId()));
}
for (Device devices : device) {
cnd.or("q_deviceId", "=", devices.getId());
}
sql.setVar("cnd", cnd);
Sql sql = Sqls.create("select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity $cnd )");
Cnd cnd = Cnd.NEW();
for (PreinstallApk preinstallApk : preinstallApks) {
cnd.or("q_apkId", "=", preinstallApk.getId()); // 怎么有个cnd1乱入, 已删
}
for (Device devices : device) {
cnd.or("q_deviceId", "=", devices.getId());
}
sql.setVar("cnd", cnd);
这样写获取不到最新日期的记录 都是第一次的记录
select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity WHERE q_apkId=1 OR q_apkId=1 AND q_apkId=39 OR q_apkId=39 AND q_deviceId=112 OR q_deviceId=112 )
--------[ActivatingQuantity [id=2192, apkId=1, deviceId=112, createtime=2017-11-28 16:31:58.0, time=1], ActivatingQuantity [id=2193, apkId=39, deviceId=112, createtime=2017-11-28 16:31:58.0, time=1]]
为什么 没有相对软件的记录 这么查询其他软件的记录
=---1 WHERE q_apkId=39 OR q_apkId=39 OR q_apkId=39
=--- WHERE q_apkId=39 OR q_apkId=39 OR q_apkId=39 OR q_deviceId=112 OR q_deviceId=112
2017-11-29 10:13:54,622 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity WHERE q_apkId=? OR q_apkId=? OR q_apkId=? OR q_deviceId=? OR q_deviceId=? )
| 1 | 2 | 3 | 4 | 5 |
|----|----|----|-----|-----|
| 39 | 39 | 39 | 112 | 112 |
For example:> "select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity WHERE q_apkId=39 OR q_apkId=39 OR q_apkId=39 OR q_deviceId=112 OR q_deviceId=112 )"
--------select * from t_activating_quantity where q_createtime in (select max(q_createtime) from t_activating_quantity WHERE q_apkId=39 OR q_apkId=39 OR q_apkId=39 OR q_deviceId=112 OR q_deviceId=112 )
--------[ActivatingQuantity [id=2410, apkId=1, deviceId=112, createtime=2017-11-28 17:59:37.0, time=2]]
添加回复
请先登陆