使用sql来解决1道智力题

昨天同事出一道题,
一问:有六个小朋友去玩具店里买玩具,他们分别带了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)

其实这和写程序来求解是一样的道理.

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值