sql语句问题 - Oracle / 基础和管理
id a b
-----------
1 2 12
1 1 100
1 2 123
1 1 130
1 2 153
1 1 171
1 1 188
1 2 200
1 2 222
1 1 234
1 2 333
1 2 344
1 2 411
原始数据按照b列排序,正常数据a列是1,2交替,然后分别取得b列的值
如果a列开始数据是2,舍去2对应的b列的值
如果a列出现相同的1,b2取下个1对应的b列的值
如果a列出现相同的2,舍去下个2对应的b列的值
想输出的结果
id b1 b2
-----------------
1 100 123
1 130 153
1 171 188
1 188 200
1 234 333
请各位高手帮帮忙,写条sql,先谢谢了
sql估计够呛了
不太明白
原始数据按照b列排序,正常数据a列是1,2交替,然后分别取得b列的值
如果a列开始数据是2,舍去2对应的b列的值
如果a列出现相同的1,b2取下个1对应的b列的值
如果a列出现相同的2,舍去下个2对应的b列的值
上面是原始数据表,下面是想要得到的结果,你结合数据看一下就明白了
SQL code:
create table test1(id number(18,0), a number(18,0), b number(18,0));
insert into test1(id, a, b) values(1,2,12);
insert into test1(id, a, b) values(1,1,100);
insert into test1(id, a, b) values(1,2,123);
insert into test1(id, a, b) values(1,1,130);
insert into test1(id, a, b) values(1,2,153);
insert into test1(id, a, b) valu
相关问答:
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
CREATE OR REPLACE PROCEDURE usp_refreshTopN
IS
BEGIN
--文档
INSERT INTO topnresource(resourceId,title,type,cover,brief,properUser,tag,clickAmount,createDate,topNCreateDate,o ......
通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......