求一SQL语句
按要求统计下面两个字段
F_Bh F_Je
1 10
2 20
3 10
5 50
6 10
8 10
9 20
要求得到结果如下
Bh1 Bh2 Je
1 3 40
5 6 60
8 9 30
F_Bh 编号连续的则统计一次,并且记录其实编号和终止编号
有意思
不明白
SQL code:
/*
*************************************
* T-MAC 小编 *
* -->努力成长中 *
* -->梦想DBA *
*************************************
*/
if OBJECT_ID('tb') is not null
drop table tb
go
create table tb (F_Bh int, F_Je int)
insert tb select
1 ,10 union select
2 ,20 union select
3 ,10 union select
5 ,50 union select
6 ,10 union select
8 ,10 union select
9 ,20
select Bh1=MIN(f_bh),
Bh2=MAX(f_bh),
Je=SUM(f_je)
from (
select rn=ROW_NUMBER() over(order by f_bh)-f_bh,* from tb) k
group by rn
order by Bh1
(7 行受影响)
Bh1 Bh2 Je
----------- ----------- -----------
1 3 40
5 6 60
8 9 30
SQL code:
declare @t table(F_Bh int,F_Je int)
insert into @t select 1,10
insert into @t select 2,20
inser
相关问答:
大家帮忙看看这2个sql语句哪个查询的速度更快点。谢谢帮忙。比较着急。在做性能测试。
select * from
表A LEFT OUTER JOIN 表B ON (表A.id || ' ' =表B.id) ,表C , 表D, 表E
Where其他条件
select * ......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
pl/Sql如何查询字符串包括%,
例如:TABLE a
columnA
'222'
'33%44'
如何查询表a中columnA字段中哪些行包含'%'
谢谢
select * from a
where columna like '%/%%' escape '/'
UP
SELECT * from a ......
题目:把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;
sql语句:
update SC set score=(SELECT avg(SC_2.score)
from SC SC_2
WHERE S ......
一个很奇怪的问题
SQL code
select * from Gprs_DataInof
--可以查到所有的数据
select * from Gprs_DataInof where DataTime between 1900-10-16 1:01:00' and '2009-10-20 1:01:00'
--一条数据 ......