一张表a,根据条件查询得到结果:
prodname    province
  a1          b1
  a2          b2
我想问的是如何用sql语句,让这两行数据在一行中显示:
prodname    province
  a1和a2      b1和b2在线等,多谢了

解决方案 »

  1.   

    就只有两行???
    select min(prodname)||'和'||max(prodname) prodname,
           mim(province)||'和'||max(province) province
    from a
      

  2.   

    select substr(max(sys_connect_by_path(PRODNAME, '和')), 2) PRODNAME, 
           substr(max(sys_connect_by_path(PROVINCE, '和')), 2) PROVINCE from (
    select PRODNAME, PROVINCE, rownum n1 from a)
    start with n1=1
    connect by n1=rownum
      

  3.   

    select 
         (select prodname from a where prodname =a1)||'和'
         (select prodname from a where prodname =a2)||'和'
         (select prodname from a where prodname =a3)||'和'
          ....
         (select prodname from a where prodname =an') prodname,
         (select province from a where prodname =a1)||'和'
         (select province from a where prodname =a2)||'和'
         (select province from a where prodname =a3)||'和'
          ....
         (select province from a where prodname =an')province 
    from dual;