编辑:一直使用SQLiteBrowser作为IDE \ Tool
不是SQLite的常用用户 - 请原谅我的无知。 下面的查询是更大查询的一部分;
SELECT DISTINCT T1.Material AS "Diameter",
T2.sLength AS "0-110mm",
T3.sLength AS "110-160mm",
T4.sLength AS "225-300mm",
T5.sLength AS "300-450mm",
T6.sLength AS "450-600mm",
T7.sLength AS "600mm-"
FROM "mycte" T1
LEFT JOIN "mycte" T2
ON T1.Material = T2.Material
AND T2.Diameter = "0-110mm"
LEFT JOIN "mycte" T3
ON T1.Material = T3.Material
AND T3.Diameter = "110-160mm"
LEFT JOIN "mycte" T4
ON T1.Material = T4.Material
AND T4.Diameter = "225-300mm"
LEFT JOIN "mycte" T5
ON T1.Material = T5.Material
AND T5.Diameter = "300-450mm"
LEFT JOIN "mycte" T6
ON T1.Material = T6.Material
AND T6.Diameter = "450-600mm"
LEFT JOIN "mycte" T7
ON T1.Material = T7.Material
AND T7.Diameter = "600mm-"
WHERE T1.Material <> ''
虽然我在别名中使用带有单个连字符\ _减号的别名,但字段返回空。 如果我重命名别名&#34; 0-110mm&#34;到&#34; 0--110mm&#34;,列的字段返回数据。 看起来似乎只有一个连字符\_dé正在搞乱。
有什么想法吗? 提前谢谢。
答案 0 :(得分:0)
最好的我已经设法提出这个。只需要处理名称中的尾随空格。
SELECT DISTINCT
T1.Material AS "Diameter"
,T2.sLength AS [0-110mm ]
,T3.sLength AS [110-160mm ]
,T4.sLength AS [160-225mm ]
,T5.sLength AS [225-300mm ]
,T6.sLength AS [300-450mm ]
,T7.sLength AS [450-600mm ]
,T8.sLength AS [600mm- ]
FROM "MyCTE" T1
LEFT
JOIN "MyCTE" T2 ON T1.Material = T2.Material AND T2.Diameter = "0-110mm"
LEFT
JOIN "MyCTE" T3 ON T1.Material = T3.Material AND T3.Diameter = "110-160mm"
LEFT
JOIN "MyCTE" T4 ON T1.Material = T4.Material AND T4.Diameter = "160-225mm"
LEFT
JOIN "MyCTE" T5 ON T1.Material = T5.Material AND T5.Diameter = "225-300mm"
LEFT
JOIN "MyCTE" T6 ON T1.Material = T6.Material AND T6.Diameter = "300-450mm"
LEFT
JOIN "MyCTE" T7 ON T1.Material = T7.Material AND T7.Diameter = "450-600mm"
LEFT
JOIN "MyCTE" T8 ON T1.Material = T8.Material AND T8.Diameter = "600mm-"
答案 1 :(得分:0)
我不确定您使用的是哪个版本的SQLite,但以下小提示演示了您的初始方法是否正常工作:
http://sqlfiddle.com/#!7/20222/1
CREATE TABLE test
(
col1 VARCHAR(100)
);
INSERT INTO test
(col1)
SELECT 'foo'
SELECT col1 AS "col-1"
FROM test
答案 2 :(得分:-1)
不要使用双引号或方括号作为别名。请改用单引号。这可能会解决问题。前几天我遇到了类似的问题,不一样但是相似。
https://www.sqlite.org/lang_keywords.html
&#39;关键字&#39;单引号中的关键字是字符串文字。 &#34;关键字&#34;双引号中的关键字是标识符。 [keyword]方括号中的关键字是标识符。这不是标准的SQL。此引用机制由MS Access和SQL Server使用,并包含在SQLite中以实现兼容性。