Marcatectura
Marcatectura

Reputation: 1695

No such column error when replacing comma in integer field for percentage calculation

I'm having trouble calculating a percentage from integer columns in two tables in SQLite. My employeetrained and employeetotal data are both integers, but one has commas. I'm using REPLACE to take care of that and create a new column with an alias, but I can't seem to use that alias for my calculation; I'm getting an error -- Result: no such column: trainedint Below is my data:

TRAINED table

id name employeetrained
01331 Cyberdyne Systems 41,877
18774 Nakatomi Corporation 35,411
93571 Tyrell Corporation 84,000

CORPORATIONS table

id name employeetotal
01331 Cyberdyne Systems 48872
18774 Nakatomi Corporation 94547
93571 Tyrell Corporation 247440

And my query:

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

Upvotes: 0

Views: 31

Answers (0)

Related Questions