zoukankan      html  css  js  c++  java
  • 经典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 
     
    
    
  • 相关阅读:
    href="#" 是什么意思?
    JavaScript匿名自执行函数~function(){}
    var $this = $(this)是什么意思?
    .Ajax
    myeclipse 的Customize Perspective 没有反应
    JS中的this指向问题
    JS中$含义和用法
    JS中sessionstorage的getItem/setItem/removeItem/clear
    JS中的top是什么?
    CAD常用命令大全
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/1810461.html
Copyright © 2011-2022 走看看