只保留最后的检索语句中的order by ,其余前面的都去掉,再试一下!create PROCEDURE cf_Jxs_AreaTopAs
select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='北京' unionselect top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='上海' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='杭州市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='广州市'union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='湖南省'union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='湖北省'union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='天津'union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='成都市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='沈阳市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='济南市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='长春市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.province='重庆' 
union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='南京市' union select top 1  l.companyname,l.companytype,c.cuxiao_topic,c.info_id,c.dateandtime,c.jxs_id from tbl_jxs_cxinfo c,tbl_company_list l
where l.co_id=c.jxs_id and l.city='苏州市' order by c.info_id desc

解决方案 »

  1.   

    是的,不能用order by!用union起来的纪录,会自动按照第一个栏位,第2个栏位,第3个栏位,...
      如果union all则不改变原来的顺序,就按原来的前后
    例如数据:
    select auto_id,cswh_csid from cs_wh where cswh_vend = 'b102' and cswh_csid = '0507110001'
    union 
    select auto_id,cswh_csid  from cs_wh where cswh_vend = 'b100' and cswh_csid = '0507110001'select auto_id,cswh_csid from cs_wh where cswh_vend = 'b102' and cswh_csid = '0507110001'
    union  all
    select auto_id,cswh_csid  from cs_wh where cswh_vend = 'b100' and cswh_csid = '0507110001'
    /*
    auto_id              cswh_csid  
    -------------------- ---------- 
    608525               0507110001
    608570               0507110001
    608571               0507110001
    608572               0507110001(4 row(s) affected)auto_id              cswh_csid  
    -------------------- ---------- 
    608570               0507110001
    608571               0507110001
    608572               0507110001
    608525               0507110001(4 row(s) affected)
    */
      

  2.   

    select *
    from
          (
            select * from 表....
            union
            select * from 表....
            union
            ........
          )T
    order by info_id