mysql pivot

Solutions on MaxInterview for mysql pivot by the best coders in the world

showing results for - "mysql pivot"
Louka
01 Jul 2017
1SELECT          -- Total invoices per gender
2  sums.F AS "Women", sums.M AS "Men", sums.M + sums.F AS "Total"
3FROM (
4  SELECT
5    SUM( IF(gender='M', invoice, 0) ) As 'M',
6    SUM( IF(gender='F', invoice, 0) ) As 'F'
7  FROM sales
8) AS sums;
9-- Table Sales:
10CREATE TABLE sales (
11    gender VARCHAR(1),      -- 'F' or 'M'
12    invoice NUMBER
13);