zoukankan      html  css  js  c++  java
  • sqlserver 同一列不同数据放到一行不同列

    1、所有数据

          

     2、建立临时表名称、类型只显示一列

      ①、sql

     --临时表插入筛选数据
      select * into #templet  from 
      (select _hour.Id from (select id,ROW_NUMBER()OVER( partition by Name,Type order by Type desc) Rank from [WeChatApp].[dbo].[Templates])_hour where Rank=1) tab;
      --查询筛选后数据
      select * from [WeChatApp].[dbo].[Templates] where Id in(select id from #templet)

       ②、结果

      

    3、分组不同列显示同一列

           ①、sql

    select Name
      ,max( case when Type=1 then 1 else 0 end )Type1
      ,max( case when Type=2 then 2 else 0 end )Type2
      ,max( case when Type=3 then 3 else 0 end )Type3
      from [WeChatApp].[dbo].[Templates] where Id in (select id from #templet)
      group by Name;

      ②、结果

        

           ③、转换文字列

    select Name
      ,max( case when Type=1 then '初级' else null end )Type1
      ,max( case when Type=2 then '中级' else null end )Type2
      ,max( case when Type=3 then '高级' else null end )Type3
      from [WeChatApp].[dbo].[Templates] where Id in (select id from #templet)
      group by Name;

             ④、查询结果

                   

  • 相关阅读:
    页面时如何加载的
    Node的运行
    js 和css 的压缩工具。
    js 判断ie
    208-Servlet初始化是什么?
    207-乐观锁与悲观锁?
    206-navicat一直连接不上mycat是怎么回事?
    205-springboot如何集成reids?
    204-jdbc如何连接数据库
    203-全局变量char的默认值是多少?
  • 原文地址:https://www.cnblogs.com/study10000/p/13036872.html
Copyright © 2011-2022 走看看