无外键关联的2个表的查询
程序员文章站
2022-04-21 10:12:35
...
if(null!=level && !"".equals(level))
{
//有条件查询
sql = "SELECT " +
"E.ENUMID," +
"E.role," +
"E.PRI," +
"E.DOMAIN," +
"E.URL," +
"P.PROVINCE_NAME," +
"E.DISTINCT_ID," +
"E.DESCRIPTION " +
"FROM ENUM_INFO E, PROVINCE_INFO P " +
"WHERE TO_NUMBER(SUBSTR(E.HOME_ID, 4, 3)) = P.PROVINCE_ID AND role='"+level+"' " +
"UNION ALL " +
"SELECT " +
"E.ENUMID," +
"E.role," +
"E.PRI," +
"E.DOMAIN,E.URL," +
"'全国'," +
"E.DISTINCT_ID," +
"E.DESCRIPTION FROM ENUM_INFO E " +
/*"WHERE E.role = 1 AND " +*/
"WHERE role='"+level+
"' AND e.home_id='"+SysConstants.FIRST_ENUM_HOMEID+"' " +
"ORDER BY role ASC";
}
else
{
//无条件查询
sql = "SELECT " +
"E.ENUMID," +
"E.role," +
"E.PRI," +
"E.DOMAIN," +
"E.URL," +
"P.PROVINCE_NAME," +
"E.DISTINCT_ID," +
"E.DESCRIPTION " +
"FROM ENUM_INFO E, PROVINCE_INFO P " +
"WHERE TO_NUMBER(SUBSTR(E.HOME_ID, 4, 3)) = P.PROVINCE_ID " +
"UNION ALL " +
"SELECT " +
"E.ENUMID," +
"E.role," +
"E.PRI," +
"E.DOMAIN,E.URL," +
"'全国'," +
"E.DISTINCT_ID," +
"E.DESCRIPTION FROM ENUM_INFO E " +
" WHERE " +
/*"E.role='1' OR E.ROLE='2' " +
" AND " +*/
"e.home_id='"+SysConstants.FIRST_ENUM_HOMEID+"' " +
"ORDER BY role ASC";
}
上一篇: android Emoji的处理
下一篇: JPA单项一对多外键关联
推荐阅读
-
基于SQL2005 SQL2008 表结构信息查询升级版的详解(含外键信息)
-
MySQL删除表的时候忽略外键约束的简单实现
-
MySQL删除有外键约束的表数据方法介绍
-
Django中ORM外键和表的关系详解
-
关系型数据库的外键约束与关联
-
MySQL:如何导入导出数据表和如何清空有外建关联的数据表
-
oracle数据库的同义词Synonym与dblink关联,从而可以直接查询远程数据库的表,不用指定用户和@指定dblink名称
-
Oracle系统表外键的更名
-
用一张表来存储数据状态,并且可以进行多状态精确查询;使用二进制来表示数据状态,并且是可以无顺序的状态;解决使用中间表来存储数据的多状态;数据状态还可以这么玩;
-
牛客SQL练习-46-在audit表上创建外键约束,其emp_no对应employees_test表的主键id