sql GROUP BY单独列出结果

时间:2017-06-23 14:57:27

标签: mysql

我有一个我在客户端组中创建的表,并使用GROUP_CONCAT(产品)AS products2准备用逗号分隔的产品。除了我需要将Group的产品列表分别列为一列而不是逗号分隔。

简而言之,我需要将该组合在一起的产品列入一行。

SELECT customer, GROUP_CONCAT (product) AS products2 FROM sales GROUP BY customer

表。

    CREATE TABLE IF NOT EXISTS `vendas` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customer` int(11) NOT NULL,
  `product` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Extraindo dados da tabela `vendas`
--

INSERT INTO `vendas` (`id`, `customer`, `product`) VALUES
(1, 10, 2),
(2, 10, 1),
(3, 11, 1),
(4, 11, 2);

0 个答案:

没有答案