• 经典SQL语句,可以让行的数据当列来显示


    SELECT TOP 100 PERCENT MAX(DISTINCT id) AS id, product_no, color, color2, 
          product_type, SUM(number4) AS number, 
          SUM(CASE WHEN ((product_size = '34' AND product_class = '女鞋') OR
          (product_size = '38' AND product_class = '男鞋') OR
          (product_class NOT IN ('女鞋', '男鞋'))) THEN number4 ELSE 0 END) AS size34, 
          SUM(CASE WHEN ((product_size = '35' AND product_class = '女鞋') OR
          (product_size = '39' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size35, SUM(CASE WHEN ((product_size = '36' AND product_class = '女鞋') OR
          (product_size = '40' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size36, SUM(CASE WHEN ((product_size = '37' AND product_class = '女鞋') OR
          (product_size = '41' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size37, SUM(CASE WHEN ((product_size = '38' AND product_class = '女鞋') OR
          (product_size = '42' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size38, SUM(CASE WHEN ((product_size = '39' AND product_class = '女鞋') OR
          (product_size = '43' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size39, SUM(CASE WHEN ((product_size = '40' AND product_class = '女鞋') OR
          (product_size = '44' AND product_class = '男鞋')) THEN number4 ELSE 0 END) 
          AS size40, MAX(price) AS price, MAX(price2) AS price2, MAX(price3) AS price3, 
          MAX(price4) AS price4
    FROM dbo.tbl_product_store
    WHERE (isnum2 = 1) AND (number4 > 0)
    GROUP BY product_no, color, color2, product_type
    ORDER BY product_no DESC 
     
    
    
  • 相关阅读:
    斯巴鲁汽车 技术文档下载方法
    博客园 Mac Windows Linux 客户端 源码 electron 开发
    博客园 Mac客户端 1.0 源码
    博客园 Mac客户端 2.0-Beta
    Python数据分析的库
    排版助手Gidot
    离线下载pip包进行安装
    Anaconda+用conda创建python虚拟环境
    ? Install Telegram on Ubuntu via PPA
    使用BeautifulSoup删除html中的script、注释
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/1810461.html
Copyright © 2020-2023  润新知