Oracle数据库中的复合选择查询

时间:2012-07-18 16:12:32

标签: oracle select oracle10g

我有一张桌子mealdb,有三个字段即。 "userid", "timeofday", "daydate"(所有varchar2)。 timeofday可以有两个值,“中午”或“下午”。现在我想计算针对给定用户标识的下午总数。我试过像

select sum(timeofday) 
  from mealdb 
 where timeofday='afternoon' where userid='1200';

但它在Oracle 10g中出错。

如何解决此问题?

3 个答案:

答案 0 :(得分:2)

只允许使用一个WHERE个关键字。

使用ANDOR

等布尔运算符添加其他条件
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就是。