SQL code:
---测试数据---
if object_id('[grxs]') is not null drop table [grxs]
go
create table [grxs]([tc_name] varchar(2),[tc_sex] int,[sj] datetime)
insert [grxs]
select '张',-1 ,'2010-2-4' union all
select '张',-3 ,'2010-2-4' union all
select '王',-2 ,'2010-2-4' union all
select '李',- ......
表A结构及数据示例如下:
NAME TIME1 TIME2
---------------------------------
TOM 2009-01-01 2009-01-02
JACK 2010-01-01 2010-02-03
TOM 2009-01-01 2009-07-02
TOM ......
排序前
5 245 405
5 245 406
5 239 396
5 239 395
5 240 398
5 240 397
5 241 399
5 241 400
5 242 401
5 242 402
要求排序后
5 245 405
5 245 406
5 239 395
5 239 396
5 240 397
5 240 397
5 241 398
5 241 400
5 242 401
5 242 402
先谢谢了。
......
表:
group value
1 1
1 2
1 3
2 1
2 3
3 1
3 3
每一组中(id)取一个值, ......
执行该段
select * from
(
select a.*,b.register_date,b.staff_msisdn,b.归属机构
from (select * from lmf_hlwzx_200912 where to_char(create_time,'yyyymm')=200912) a,
(select * from qz_jj_1.ban_dj_200912_done where 积分项目 like '%专线%') b
where a.paymen ......
select
sum(case a when 0 then b else 0 end) as qty1,
sum(case a when 1 then b else 0 end) as qty2,
sum(b) - qty1 - qty2 as qty3 //qty3我是想实现这样的功能,但我知道这样写肯定不对,不知道怎么能实现?
from table1
group by...
SQL code:
select
sum(case a when 0 then b else 0 end ......