我有一张桌子mealdb
,有三个字段即。 "userid", "timeofday", "daydate"
(所有varchar2
)。 timeofday
可以有两个值,“中午”或“下午”。现在我想计算针对给定用户标识的下午总数。我试过像
select sum(timeofday)
from mealdb
where timeofday='afternoon' where userid='1200';
但它在Oracle 10g中出错。
如何解决此问题?
答案 0 :(得分:2)
只允许使用一个WHERE
个关键字。
使用AND
,OR
select count(*)
from mealdb
where timeofday='afternoon'
and userid='1200';
答案 1 :(得分:1)
select count(1)
from mealdb
where timeofday='afternoon' and userid='1200';
答案 2 :(得分:0)
尝试select count(timeofday) from mealdb where timeofday='afternoon' and userid='1200'
您需要使用Count
而不是Sum
并使用and
,而您的第二个where
就是。