我在从 SQLite 的两个表中的整数列中计算百分比时遇到问题。我的employeetrained 和employeetotal 数据都是整数,但其中一个有逗号。我正在使用 REPLACE 来解决这个问题并创建一个带有别名的新列,但我似乎无法使用该别名进行计算;我收到错误-- Result: no such column: trainedint
以下是我的数据:
训练表
ID | 姓名 | 受过培训的员工 |
---|---|---|
01331 | Cyberdyne 系统 | 41,877 |
18774 | 中富公司 | 35,411 |
93571 | 泰瑞尔公司 | 84,000 |
公司表
ID | 姓名 | 员工总数 |
---|---|---|
01331 | Cyberdyne 系统 | 48872 |
18774 | 中富公司 | 94547 |
93571 | 泰瑞尔公司 | 247440 |
我的查询:
CREATE TEMPORARY TABLE "trainedpercent" AS SELECT trained.id, trained.employeetrained, corporations.employees, corporations.name,
REPLACE(employeetrained, ',', '') AS trainedint,
((trainedint/employees)*100.0) AS TrainedPercent
FROM trained
INNER JOIN corporations
ON trained.id = corporations.id
ORDER BY TrainedPercent