是否可以获得Select语句的总和?
sum(Select (VPTOTALS.TIMEINSECONDS/3600)
from Table XXXX
inner join Table YYYY
on ..... = ......
and ..... = .....) as Hours`
我已经看过它,但我无法让它为我工作。我收到语法错误sum(Select
和)
作为小时
由于
答案 0 :(得分:0)
没有。您执行{__esModule: true, default: ƒ}
default
:
ƒ Factory()
createQueryString
:
ƒ (state, options)
version
:
"2.2.1"
connectors
:
[Exception: ReferenceError: You can't access to 'instantsearch.connectors' directly from the ES6 build. Import the connectors this way 'import {connectSearchBox} from "instantsearch.js/connectors"' at Function.get (http://localhost:8100/build/0.js:9985:11) at Function.remoteFunction (<anonymous>:2:14)]
length
:
0
name
:
"Factory"
prototype
:
EventEmitter {constructor: ƒ, addWidget: ƒ, start: ƒ, createURL: ƒ, _render: ƒ, …}
widgets
:
[Exception: ReferenceError: You can't access to 'instantsearch.widgets' directly from the ES6 build. Import the widgets this way 'import {SearchBox} from "instantsearch.js/widgets"' at Function.get (http://localhost:8100/build/0.js:9979:11) at Function.remoteFunction (<anonymous>:2:14)]
get connectors
:
ƒ get()
get widgets
:
ƒ get()
__proto__
:
ƒ InstantSearch(_ref)
[[FunctionLocation]]
:
to-factory.js:5
[[Scopes]]
:
Scopes[3]
__esModule
:
true
__proto__
:
Object
的{{1}}:
select
答案 1 :(得分:0)
您可以使用:
SELECT SUM(VPTOTALS.TIMEINSECONDS/3600)
FROM Table XXXX
INNER JOIN Table YYYY on ..... = ......
and ..... = .....)
这将自动对整个查询求和,因为select语句中没有其他非聚合列。
如果您想在查询中包含非聚合,则需要group by子句,以便用该变量对其进行拆分:
SELECT type,
SUM(VPTOTALS.TIMEINSECONDS/3600)
FROM Table XXXX
INNER JOIN Table YYYY on ..... = ......
and ..... = .....)
GROUP BY type
答案 2 :(得分:0)
如果这是一个相关的子查询,那么它可以是
Select t1.Col1
, sum( select sum(somecol) from sometbl t2 where t2.fk = t1.id )
as hours
From outertbl t1
Group by t1.col1
但是这个例子是人为的而且没有效率。