关于mysql中“group by”语句的简短问题:
我当前的数据库结构如下所示:
CREATE TABLE TableName
(
ID int primary key,
name varchar(255),
number varchar(255)
);
INSERT INTO TableName
(ID, name, number)
VALUES
(1, "Test 1", "100000"),
(2, "Apple", "200000"),
(3, "Test 1 beta", "100000"),
(4, "BLA", "300000"),
(5, "ABU", "400000"),
(6, "CBA", "700000"),
(7, "ABC", "600000"),
(8, "Orange - Test", "400000"),
(9, "ABC", "");
我目前的陈述如下:
SELECT name, number, count(*) as Anzahl
FROM TableName
group by name,number
使用此语句,结果如下所示:
NAME NUMBER ANZAHL
ABC 1
Test 1 100000 2
Apple 200000 1
BLA 300000 1
ABU 400000 2
ABC 600000 1
CBA 700000 1
但是值“ABC”不会合并。
结果应如下所示:
NAME NUMBER ANZAHL
Test 1 100000 2
Apple 200000 1
BLA 300000 1
ABU 400000 2
ABC 600000 2
CBA 700000 1
任何想法如何工作?
SQLFiddle: http ://sqlfiddle.com/#!2/dcbee/1
该解决方案必须对 +1 000 000 行之类的内容有效