日期:2014-05-17  浏览次数:20829 次

怎样把三条SQL语句连接起来,
怎样把三条SQL语句连接起来,或是后两条用 或 语句写为一条也可以
sSQL1= "select hacref.session.* ,hacref.session_2.* from hacconf.resource,hacconf.auditor_session_author,hacref.session left join hacref.session_2 on(id = session_id) where " "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr;sSQL+= " and endtime > 1";
sSQL1+=" and hacref.session.appname=hacconf.resource.name and hacconf.resource.dev_id=hacconf.auditor_session_author.dev_id ";
str.Format("and hacconf.auditor_session_author.manager_id=%d",theApp.m_nCurUserID);
sSQL1+=str;
   
sSQL2="select distinct * from hacref.session left join hacref.session_2 on(id = session_id) where "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 1";  
  
sSQL3=" select distinct * from hacref.session left join hacref.session_2 on(id = session_id) where " "starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 3 and serverIP="[UNKNOWN]"";

------解决方案--------------------
"starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 1 or (starttime <= " + toTimeStr + " and starttime >= " + fromTimeStr and endtime = 3 and serverIP="[UNKNOWN]")";
------解决方案--------------------
Union All
------解决方案--------------------
或者
select * from tb where id=1
union
select * from tb where id=2;

注意第一句后面不能有分号