数据库-select查询语句(续1)

1.在面试过程中多次碰到两道SQL查询的题目,一是查询A(ID,Name)表中第31至40条记录,ID作为主键可能是不是连续增长的列。

select id,name from 

(select id, name,rownum r from A) t

where t.r>30 and t.r<41;

升级版:将表A(id,name)按id升序排列,并取出第6至10行的记录。

select id ,name from

(

select id,name,rownum r from

(

select id,name from A order by asc

)

)where r>5 and r<11;


2.SQL语句面试题,表内容如下:

2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
如果要生成下列结果,该如何写sql语句?

                  胜 负

2005-05-09 2 2

2005-05-10 1 2

解:

create table t  (

t_date  verchar2(10),

score   verchar2(2),

);

insert into t values ('2005-05-09','胜');insert into t values ('2005-05-09','胜');

insert into t values ('2005-05-09','负');insert into t values ('2005-05-09','负');

insert into t values ('2005-05-10','胜');

insert into t values ('2005-05-10','负');insert into t values ('2005-05-10','负');

select  t_date, 胜,负  from  

(select t_date,count(*) 胜 from t where score='胜' group by t_date) t1

join   (select t_date,count(*) 负 from t where score='负' group by t_date) t2

on(t1.t_date=t2.t_date);

语句面试题,关于

group by 

表内容:

 

2005-05-09 

 

2005-05-09 

 

2005-05-09 

 

2005-05-09 

 

2005-05-10 

 

2005-05-10 

 

2005-05-10 

 

如果要生成下列结果

该如何写

sql

语句

            

 

 

2005-05-09 2 2 

2005-05-10 1 2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值