我使用表user和avgEncHr(以及更多不相关的列)创建了表ProductionByUser。我正在尝试计算每个avgEncHr的百分比,并想调用该PercAvgEncHr。我只想显示PercAvgEncHr> 25的所有列。
我尝试了很多不同的操作,例如更改表和列等,这给了我错误:操作数应包含1列。
SET @count = (SELECT COUNT(user)
FROM productivityByUser);
SET @totalAvgEncHr = (SELECT SUM(avgEncHr)
FROM productivityByUser);
-- ALTER TABLE productivityByUser
-- ADD COLUMN PercAvgEncHr INTEGER;
SET @PercAvgEncHr = (
SELECT avgEncHr, @totalAvgEncHr,(avgEncHr) / ((SUM(avgEncHr)) * 100)
FROM productivityByUser);
SELECT * FROM productivityByUser WHERE (PercAvgEncHr > 25);
最佳答案
SET @PercAvgEncHr = ( SELECT avgEncHr/ SUM(avgEncHr) * 100 FROM productivityByUser );
现在,您只存储一个记录。希望能帮助到你!