📜  mysql pivot - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:06.649000             🧑  作者: Mango

代码示例1
SELECT          -- Total invoices per gender
  sums.F AS "Women", sums.M AS "Men", sums.M + sums.F AS "Total"
FROM (
  SELECT
    SUM( IF(gender='M', invoice, 0) ) As 'M',
    SUM( IF(gender='F', invoice, 0) ) As 'F'
  FROM sales
) AS sums;
-- Table Sales:
CREATE TABLE sales (
    gender VARCHAR(1),      -- 'F' or 'M'
    invoice NUMBER
);