欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

无外键关联的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";
				}
 

 

 

 

相关标签: SQL