我有一个包含名称、color1、color2、color3 和其他列(SQLite)的表:
CREATE TABLE data (name TEXT, lvlavailable INTEGER, lvlExtra TEXT,
color1 TEXT, color2 TEXT, color3 TEXT);
当前数据
INSERT INTO "someTable" VALUES ("name","Amarillo","NoColor","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","NoColor","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Azul","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Azul","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Rojo","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Rojo","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Rojo","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Rojo","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Rojo","Verde");
INSERT INTO "someTable" VALUES ("name","Amarillo","Verde","NoColor");
INSERT INTO "someTable" VALUES ("name","Amarillo","Violeta","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","NoColor","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","NoColor","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","Amarillo","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","Amarillo","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","Amarillo","NoColor");
INSERT INTO "someTable" VALUES ("name","Azul","Amarillo","Rojo");
在这种情况下,列名是无关紧要的 *我知道插入不正确,因为列数,但我想你明白了*
当前选择语句:
SELECT name,
color1,
CASE WHEN color2 = 'NoColor' THEN '' ELSE color2 END as color2,
CASE WHEN color3 = 'NoColor' THEN '' ELSE color3 END as color3
FROM someTable
GROUP BY color1,color2,color3,name
案例用于其他目的
目前的结果:
name Amarillo
name Amarillo
name Amarillo Azul
name Amarillo Azul
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo Verde
name Amarillo Verde
name Amarillo Violeta
name Azul
name Azul
name Azul Amarillo
name Azul Amarillo
name Azul Amarillo
name Azul Amarillo Rojo
颜色的名称是西班牙语,对此感到抱歉
期望的结果:
name Amarillo
name Amarillo
name Amarillo Azul
name Amarillo Azul
name Azul Amarillo
name Azul Amarillo
name Azul Amarillo
name Azul Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo
name Amarillo Rojo Verde
name Amarillo Verde
name Amarillo Violeta
name Azul
name Azul
请注意,当它获得组 Amarillo,Azul,[empty] 时,它将继续使用 Amarillo,Azul 并在每个颜色的列中独立,但我想保持原始颜色列位置,如图所示,我不想要创建另一个列,刚刚订购。
所以,我想要的是把那些颜色相同但顺序不同的组放在一起。
那可能吗?