我需要SELECT查询结果的SUM。当我不使用SUM时,它会显示我的结果:
#include <iostream>
using namespace std;
int ascending(int x[], int npts);
int main()
{
int number[10];
int num;
cout<<"How many numbers would you like to enter? (max = 10) ";
cin>>num;
for(int i = 0; i<num; i++)
{
cout<<"Enter number ";
cin>>number[i];
}
int asc = ascending(number, num);
cout<<asc;
}
int ascending(int x[], int n)
{
int count = 0;
for(int i = 0; i<n-1; i++)
{
if(x[i]<x[i + 1])
count++;
if(count <= n - 1)
return 1;
else
return 0;
}
}
但是当我使用SUM函数时,它会显示错误:
ORA-00936:缺少表达
请问,我该如何解决?
CELKOVA_CENA
--------------------------------------------------------------------------------
80
80
120
120
120
80
150
80
150
120
150
120
.
.
.
感谢您的回复
答案 0 :(得分:1)
我认为以下方法应该根据您的期望给出结果 -
SELECT SUM(celkova_cena)
from (select (SELECT n.hodnota
FROM evidn_nastaveni n
WHERE n.popis = 'cena_krakorce'
AND n.upresneni = k.pozice) AS celkova_cena
FROM (SELECT oc.clen, oc.oddil
FROM evidn_oddily_clenove oc
INNER JOIN evidn_oddily o
ON oc.oddil = o.id
WHERE o.nazev = 'Slalom') NATURAL
JOIN evidn_krakorce k);
您需要交叉检查evidn_nastaveni
表(在内部查询中使用的内容)中是否存在重复值popis = 'cena_krakorce' and upresneni = evidn_krakorce .pozice
。
如果是这样,那么你需要在内部查询中使用任何聚合函数(MIN / MAX / SUM)。
答案 1 :(得分:0)
您可以通过将sum()
放在子查询中来解决您的具体问题:
SELECT (SELECT SUM(n.hodnota)
FROM evidn_nastaveni n
WHERE n.popis = 'cena_krakorce' AND
n.upresneni = k.pozice)
) celkova_cena
FROM . . .