oracle 关联查询 查询自身表

时间:2021-09-10 09:36:59

字段:oracle 关联查询 查询自身表oracle 关联查询 查询自身表


效果:oracle 关联查询 查询自身表

本来是select * from table 但是由于关联了一个別的表的字段,重写下查询语句效果和select * 一样,特此记录一下:

StringBuffer hql=new StringBuffer();
hql.append("select w.id as \"id\",w.title as \"title\",w.classification as \"classification\",w.keyword as \"keyword\",w.clicks as \"clicks\",w.committime as \"committime\",w.status as \"status\",w.contentss as \"contentss\" ");
//hql.append(" from knowledge w where 1=1 ");

hql.append(" from (select k.* from knowledge k inner join CLASSIFICATION c on k.classification=c.classification ");
String classification = workOrderTDTO.getClassification();
if (null != classification && !"".equals(classification)) {
hql.append(" where c.id=(select id from CLASSIFICATION a where a.classification like'%").append(classification).append("%')");
hql.append(" or c.id in(select p.id from CLASSIFICATION a inner join CLASSIFICATION p on a.id=p.perid where a.classification like '%").append(classification).append("%')");
}
hql.append(" ) w where 1 = 1 ");