select sum(value) from table where tag in ('a','b','c','d' ) group by tag order by tag

解决方案 »

  1.   

    a b c d代表字符串,有很多个,并且没法按字符串的顺序
      

  2.   

    select sum(value) from table where tag in ('a','b','c','d' ) group by tag order by tag
      

  3.   

    select tag,sum(value) from #t where tag ='d' group by tag
    union all
    select tag,sum(value) from #t where tag ='b' group by tag
    union all
    select tag,sum(value) from #t where tag ='c' group by tag
    union all
    select tag,sum(value) from #t where tag ='a' group by tag
      

  4.   

    方法二:select tag,
    case 
       when tag='d' then 1
       when tag='b' then 2
       when tag='c' then 3
       when tag='a' then 4
    end Sn,sum(value) from #t where tag in ('d','b','c','a' ) group by tag order by Sn
      

  5.   

    order by charindex(tag,'a,b,c,d')or 
    如果就是 a b c d e f g
    order by tag
      

  6.   

    order by charindex(tag,'a,b,c,d')
    ---
    想法不错啊,小弟向干部你学习了。
      

  7.   

    干部是想利用charindex()返回的tag字段值在用户指定顺序字符串'a,b,c,d'中的位置进行排序。这样子用就算是想排成b,d,a,c的顺序,只需要把原先的'a,b,c,d'改成'b,d,a,c'也可以啦。真是令在下茅塞顿开,谢了。