昨天同事出一道题,
一问:有六个小朋友去玩具店里买玩具,他们分别带了14元、17元、18元、21元、25元、37元钱。他们都看中了一款游戏机,每个人所带的钱不够,但是其中有3个人的钱凑在一起正好可买2台,除去这3个人,有2人的钱凑在一起恰好能买1台。那么,这款游戏机的价格是多少?
一时兴起.
create table t1 (c1 number);
insert into t1 values(14);
insert into t1 values(17);
insert into t1 values(18);
insert into t1 values(21);
insert into t1 values(25);
insert into t1 values(37);
数据初始化之后,使用下面sql来解决.
select a.c1,b.c1,c.c1,
d.c1,e.c1,f.c1
from t1 a,t1 b,t1 c,t1 d,t1 e,t1 f
where a.c1!=b.c1
and a.c1!=c.c1
and a.c1!=d.c1
and a.c1!=e.c1
and a.c1!=f.c1
and b.c1!=c.c1
and b.c1!=d.c1
and b.c1!=e.c1
and b.c1!=f.c1
and c.c1!=d.c1
and c.c1!=e.c1
and c.c1!=f.c1
and d.c1!=e.c1
and d.c1!=f.c1
and e.c1!=f.c1
and (a.c1+b.c1+c.c1)=2*(d.c1+e.c1)
其实这和写程序来求解是一样的道理.