简体   繁体   中英

Oracle SQL Sum missing right parenthesis

I have an Oracle SQL that works on MySQL, but I get the "missing right parenthesis" when I run On Oracle.

I put it on sqlfiddle

Oracle does not have a shorthand way of using a CASE or if like MySQL. As a result you will have to use a CASE inside of your sum :

select p.id, p.name, 
  t.id as toyid, 
  t.name as toyname
from person p
inner join toys t on p.id = t.person_id
inner join 
(
  select person_id
  from toys 
  group by person_id
  having sum(case when name = 'hat' then 1 else 0 end) > 0 and
    sum(case when name = 'doll' then 1 else 0 end) > 0
) t2 
  on p.id = t2.person_id;

See SQL Fiddle with Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM