Answers for "mysql pivot"

SQL
1

mysql pivot

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
);
Posted by: Guest on May-08-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language