我是SQL和子查询的新手,当我自己运行子查询时,我得到了正确的数据输出。但是,当我运行完整查询时,我收到错误消息
SELECT *第3行的错误:ORA-00936:缺少表达式
这是我的代码:
func myLogger(message: UnsafePointer<Int8>, _ length: UInt32, _ withSysLogBanner: ObjCBool) -> Void {
print(String(format:"myLogger: %s", message))
}
_NSSetLogCStringFunction(myLogger) // Set NSLog hook.
NSLog("foo")
_NSSetLogCStringFunction(nil) // Reset to default.
NSLog("bar")
解决方案:
SELECT
MAX(
SELECT
SUM(
ALLOCATION.HourlyRate
*
ACTION.HrsWorked
)
FROM ALLOCATION
INNER JOIN ACTION
ON ((ACTION.ActId = ALLOCATION.ActId) AND (ACTION.EmpId = ALLOCATION.EmpId))
GROUP BY (ALLOCATION.ActId)
)
FROM ALLOCATION
GROUP BY (ALLOCATION.ActId)
答案 0 :(得分:0)
你需要两个括号:)
SELECT MAX ( ( SELECT SUM (ALLOCATION.HourlyRate * ACTION.HrsWorked)
FROM ALLOCATION INNER JOIN ACTION ON (ACTION.ActId = ALLOCATION.ActId) AND (ACTION.EmpId = ALLOCATION.EmpId)
GROUP BY (ALLOCATION.ActId)))
FROM ALLOCATION
GROUP BY ALLOCATION.ActId
Select into MAX必须处于paranthesis状态。
逻辑不明确。这可以为您提供每项活动的总薪酬:
SELECT ALLOCATION.ActId, SUM (ALLOCATION.HourlyRate * ACTION.HrsWorked) total_pay
FROM ALLOCATION b INNER JOIN ACTION ON ACTION.ActId = ALLOCATION.ActId AND ACTION.EmpId = ALLOCATION.EmpId
GROUP BY ALLOCATION.ActId
如果您想查看哪个活动付款最多,请按desc订购:
SELECT *
FROM ( SELECT ALLOCATION.ActId, SUM (ALLOCATION.HourlyRate * ACTION.HrsWorked) total_pay
FROM ALLOCATION b INNER JOIN ACTION ON ACTION.ActId = ALLOCATION.ActId AND ACTION.EmpId = ALLOCATION.EmpId
GROUP BY ALLOCATION.ActId)
ORDER BY total_pay DESC