title: How to Get SUM() inside GROUP_CONCAT()
body: <p>I'm trying to get of all sizes, and making result as one inside <code>GROUP_CONCAT()</code>. </p>
  
  <ul>
  <li>If there are same result inside <code>GROUP_CONCAT()</code> then, we can use <code>SUM()</code></li>
  <li>If <code>NULL</code> or other size of <code>product_size.Size_Name</code> THEN do not get a <code>SUM()</code> of this. </li>
  </ul>
  
  <p>By the way this is my query:</p>
  
  <pre><code>            SELECT
                product_table.Product_Name,
                SUM(product_quantity.Quantity) AS 'QUANTITY',
                GROUP_CONCAT(
                  product_quantity.Quantity,
                  ' box/es ',
                  product_size.Size_Name,
                  ' size' SEPARATOR '\n'
                ) AS 'SIZE'
              FROM
                product_quantity
              RIGHT JOIN
                product_table
              ON
                product_quantity.Product_ID = product_table.Product_ID
              LEFT JOIN
                product_size
              ON
                product_quantity.Size_ID = product_size.size_ID
              GROUP BY
                product_table.Product_Name ASC
  </code></pre>
  
  <p>and so this is the result :</p>
  
  <pre><code>  PRODUCT                 QUANTITY                       SIZE
  
  Hawaiian Pizza                 11                   2 - box/es Large size
                                                      3 - box/es Large size
                                                      1 - box/es Small size
                                                      5 - box/es Large size
  </code></pre>
  
  <p>And it is the correct answer on what I trying to get right now :</p>
  
  <pre><code>  PRODUCT                    QUANTITY                       SIZE
  
  Hawaiian Pizza                 11                   10 - box/es Large size
                                                      1 - box/es Small size
  </code></pre>
  
  <p>But how ? Any Idea ???</p>
  
  <p>By the way this is my table structure:</p>
  
  <p>For,</p>
  
  <p>table product:</p>
  
  <pre><code>        CREATE TABLE `product_table` (
            `Product_ID` int(40) NOT NULL,
            `Product_Name` varchar(400) NOT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
  
          INSERT INTO `product_table` (`Product_ID`, `Product_Name`) VALUES
          (1001, 'Hawaiian Pizza'),
          (1002, 'Chicken Alfredo'),
          (1003, 'Chicken Quesadillas'),
          (1004, 'Mexican Pizza'),
          (1006, 'Beef Pepperoni Pizza');
  
        ALTER TABLE `product_table`
        ADD PRIMARY KEY (`Product_ID`),
        ADD KEY `Product_ID` (`Product_ID`);
  
        ALTER TABLE `product_table`
         MODIFY `Product_ID` int(40) NOT NULL AUTO_INCREMENT,     
         AUTO_INCREMENT=1007;
  </code></pre>
  
  <p>table product_size:</p>
  
  <pre><code>        CREATE TABLE `product_size` (
            `Size_ID` int(100) NOT NULL,
            `Size_Name` varchar(50) NOT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
          INSERT INTO `product_size` (`Size_ID`, `Size_Name`) VALUES
           (1, 'Small'),
           (2, 'Medium'),
           (3, 'Extra Large'),
           (4, 'Large');
  
         ALTER TABLE `product_size`
         ADD PRIMARY KEY (`Size_ID`);
  
         ALTER TABLE `product_size`
         MODIFY `Size_ID` int(100) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
  </code></pre>
  
  <p>table product_quantity:</p>
  
  <pre><code>       CREATE TABLE `product_quantity` (
            `Quantity_ID` int(100) NOT NULL,
            `Quantity` int(100) NOT NULL,
            `Product_ID` int(100) NOT NULL,
            `Size_ID` int(100) NOT NULL
          ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
          INSERT INTO `product_quantity` (`Quantity_ID`, `Quantity`, 
         `Product_ID`, `Size_ID`) VALUES
          (18, 2, 1002, 3),
          (19, 1, 1001, 2),
          (20, 2, 1003, 1),
          (21, 3, 1002, 2),
          (22, 1, 1002, 3),
          (23, 2, 1003, 3),
          (24, 3, 1004, 4),
          (25, 1, 1003, 3),
          (26, 3, 1006, 3),
          (27, 4, 1002, 3),
          (28, 2, 1004, 4),
          (29, 4, 1002, 3),
          (30, 2, 1002, 3),
          (31, 2, 1002, 2),
          (32, 3, 1003, 3),
          (33, 23, 1002, 4);
  
          ALTER TABLE `product_quantity`
          ADD PRIMARY KEY (`Quantity_ID`),
          ADD KEY `Product_ID` (`Product_ID`),
          ADD KEY `Size_ID` (`Size_ID`);
  
          ALTER TABLE `product_quantity`
          MODIFY `Quantity_ID` int(100) NOT NULL AUTO_INCREMENT, 
          AUTO_INCREMENT=34;
  
            ALTER TABLE `product_quantity`
            ADD CONSTRAINT `product_quantity_ibfk_1` FOREIGN KEY    
            (`Product_ID`) REFERENCES `product_table` (`Product_ID`) 
            ON DELETE CASCADE ON UPDATE CASCADE,
            ADD CONSTRAINT `product_quantity_ibfk_2` FOREIGN KEY (`Size_ID`) 
            REFERENCES `product_size` (`Size_ID`) ON DELETE CASCADE ON
            UPDATE CASCADE;
  </code></pre>