Siva Academy

Youtube.com/SivaAcademy  Oracle SQL  |  PLSQL  |  SQL PLSQL Interview Questions  |  PLSQL Scenario based Interview Questions  |  Subscriber Questions & Answers

  |  SQL practical Question  |  SQL Performance Tuning  |  New Features  |  

  Trigger     |    View  

Wednesday, June 19, 2019

SQL to find list of combinations where the third dice roll equal to sum of first and second dice roll



Write a SQL to find the list of combinations, where the third rolled dice value is equal to sum of first and second rolled value

with t as (
select level r
from dual
connect by level <=6)
select t1.r ROLL1,t2.r ROLL2,t1.r + t2.r ROLL3
from t t1,t t2
where t1.r + t2.r in( 6,5,4,3,2)
order by t1.r + t2.r desc;

with t as (select level r
from dual
connect by level<=6)
select t1.r as ROLL1, t2.r as ROLL2, t3.r as ROLL3
from t t1, t t2, t t3
where (t3.r = t1.r+t2.r)
order by 3 desc;

with t as (
select level r
from dual
connect by level <=6)
select t1.r ROLL1,t2.r ROLL2,t1.r + t2.r ROLL3
from t t1,t t2
where t1.r + t2.r <= 6
order by t1.r + t2.r desc;


Write a SQL Find the list of combinations, where any roll value is equal to sum of other two rolled values

with t as (select level r
from dual
connect by level<=6)
select t1.r as ROLL1, t2.r as ROLL2, t3.r as ROLL3
from t t1, t t2, t t3
where (t3.r = t1.r+t2.r or t2.r = t1.r+t3.r or t1.r = t2.r+t3.r)
order by 3 desc;

No comments:

Post a Comment