--设定表名为T
SELECT 姓名,销售金额,销售时间,零售单号, 店名 FROM
(select 姓名,销售时间,零售单号, 店名,
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,
SUM(销售金额) OVER(PARTITION BY 零售单号) 销售金额
FROM T)
WHERE RN=1
#2
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,这句话有什么作用不太懂、?、
select max(姓名)keep(dense_rank last order by 销售金额,rowid),
sum(销售金额),
max(销售时间)keep(dense_rank last order by 销售金额,rowid),
零售单号,
max(店名)keep(dense_rank last order by 销售金额,rowid)
from 表
group by 零售单号
--设定表名为T
SELECT 姓名,销售金额,销售时间,零售单号, 店名 FROM
(select 姓名,销售时间,零售单号, 店名,
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,
SUM(销售金额) OVER(PARTITION BY 零售单号) 销售金额
FROM T)
WHERE RN=1
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select 导购员,零售日期,货位编码, 货位名称,实收金额, ROW_NUMBER() OVER(PARTITION BY 单号 ORDER BY 实收金额 DESC) RN,
sum(实收金额) OVER(PARTITION BY 单号) 实收金额 FROM
(
select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_fs.ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_fs.ls_hw_name as 货位名称,
sum(ls_take_money) as 实收金额
from ls_fs where ls_number in
(select ls_number
from ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss')
and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
having sum(ls_take_money)>=500
group by ls_number)
group by TO_CHAR(ls_date, 'YYYY-MM-DD') ,ls_number, ls_hw_code,ls_channel_person,ls_hw_name
order by ls_Number
)
) B
where RN=1
#9
你外层把单号也select出来了,里面的查询也要相应的加上
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select 导购员,零售日期,单号,货位编码, 货位名称,实收金额,
ROW_NUMBER() OVER(PARTITION BY 单号 ORDER BY 实收金额 DESC) RN,
sum(实收金额) OVER(PARTITION BY 单号) 实收金额
FROM(
select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_fs.ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_fs.ls_hw_name as 货位名称,
sum(ls_take_money) as 实收金额
from ls_fs where ls_number in
(select ls_number
from ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss') and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
having sum(ls_take_money)>=500
group by ls_number)
group by TO_CHAR(ls_date, 'YYYY-MM-DD') ,ls_number, ls_hw_code,ls_channel_person,ls_hw_name
order by ls_Number
)
)B
where RN=1
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_hw_name as 货位名称,
ROW_NUMBER() OVER(PARTITION BY ls_number ORDER BY ls_take_money DESC) RN,
sum(ls_take_money) OVER(PARTITION BY ls_number) 实收金额
FROM ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss') and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
) B
where RN=1 and 实收金额>=500
order by 单号
#14
可以了。谢谢大家!特别是大牛bw55!
#1
--设定表名为T
SELECT 姓名,销售金额,销售时间,零售单号, 店名 FROM
(select 姓名,销售时间,零售单号, 店名,
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,
SUM(销售金额) OVER(PARTITION BY 零售单号) 销售金额
FROM T)
WHERE RN=1
#2
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,这句话有什么作用不太懂、?、
#3
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,这句话有什么作用不太懂、?、
select max(姓名)keep(dense_rank last order by 销售金额,rowid),
sum(销售金额),
max(销售时间)keep(dense_rank last order by 销售金额,rowid),
零售单号,
max(店名)keep(dense_rank last order by 销售金额,rowid)
from 表
group by 零售单号
#6
select max(姓名)keep(dense_rank last order by 销售金额,rowid),
sum(销售金额),
max(销售时间)keep(dense_rank last order by 销售金额,rowid),
零售单号,
max(店名)keep(dense_rank last order by 销售金额,rowid)
from 表
group by 零售单号
我这里所说的表是经过分组函数查出来的,ROWID,在这里用不了。
#7
select max(姓名)keep(dense_rank last order by 销售金额,rowid),
sum(销售金额),
max(销售时间)keep(dense_rank last order by 销售金额,rowid),
零售单号,
max(店名)keep(dense_rank last order by 销售金额,rowid)
from 表
group by 零售单号
--设定表名为T
SELECT 姓名,销售金额,销售时间,零售单号, 店名 FROM
(select 姓名,销售时间,零售单号, 店名,
ROW_NUMBER() OVER(PARTITION BY 零售单号 ORDER BY 销售金额 DESC) RN,
SUM(销售金额) OVER(PARTITION BY 零售单号) 销售金额
FROM T)
WHERE RN=1
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select 导购员,零售日期,货位编码, 货位名称,实收金额, ROW_NUMBER() OVER(PARTITION BY 单号 ORDER BY 实收金额 DESC) RN,
sum(实收金额) OVER(PARTITION BY 单号) 实收金额 FROM
(
select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_fs.ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_fs.ls_hw_name as 货位名称,
sum(ls_take_money) as 实收金额
from ls_fs where ls_number in
(select ls_number
from ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss')
and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
having sum(ls_take_money)>=500
group by ls_number)
group by TO_CHAR(ls_date, 'YYYY-MM-DD') ,ls_number, ls_hw_code,ls_channel_person,ls_hw_name
order by ls_Number
)
) B
where RN=1
#9
你外层把单号也select出来了,里面的查询也要相应的加上
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select 导购员,零售日期,单号,货位编码, 货位名称,实收金额,
ROW_NUMBER() OVER(PARTITION BY 单号 ORDER BY 实收金额 DESC) RN,
sum(实收金额) OVER(PARTITION BY 单号) 实收金额
FROM(
select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_fs.ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_fs.ls_hw_name as 货位名称,
sum(ls_take_money) as 实收金额
from ls_fs where ls_number in
(select ls_number
from ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss') and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
having sum(ls_take_money)>=500
group by ls_number)
group by TO_CHAR(ls_date, 'YYYY-MM-DD') ,ls_number, ls_hw_code,ls_channel_person,ls_hw_name
order by ls_Number
)
)B
where RN=1
select B.导购员,B.零售日期,B.单号,B.货位编码, B.货位名称,B.实收金额 from
(select TO_CHAR(ls_date, 'YYYY-MM-DD') as 零售日期,ls_number as 单号, ls_hw_code as 货位编码,ls_channel_person as 导购员,ls_hw_name as 货位名称,
ROW_NUMBER() OVER(PARTITION BY ls_number ORDER BY ls_take_money DESC) RN,
sum(ls_take_money) OVER(PARTITION BY ls_number) 实收金额
FROM ls_fs
WHERE (LS_DATE between to_date('2014-09-01 00:00:00','yyyy-mm-dd HH24:mi:ss') and to_date('2014-09-10 23:59:59','yyyy-mm-dd HH24:mi:ss'))
) B
where RN=1 and 实收金额>=500
order by 单号