本帖最后由 cyr11 于 2011-03-30 11:59:51 编辑

解决方案 »

  1.   

    针对你提供的例子,最长的TAG不超3个,则可以使用下面SQL语句。select id,substring_index(tag,' ',1)
    from a
    union all
    select id,substring_index(substring_index(tag,' ',2),' ',-1)
    from a
    where length(tag)-length(replace(tag),' ',''))>0
    union all
    select id,substring_index(substring_index(tag,' ',3),' ',-1)
    from a
    where length(tag)-length(replace(tag),' ',''))>1
      

  2.   

    如果你TAG是无限不定长的,则你可以创建一个辅助表  seq (sno int primary key) 包含1,2,3,1000000的连接数字。然后通过SQL语句连接查询参照上例实现当然用存储过程的方法可能会更快捷一些,但应用上有限制。
      

  3.   

    动态语句 把tag里内容大概替换成select 'aa' union all select 'bb' union all select  'cc'
    然后excute这个动态语句
      

  4.   

    非常感谢各位!
    绿色php资源http://www.phpzy.com 医学考试网 http://www.bao100.com