【发布时间】:2015-10-18 03:20:20
【问题描述】:
有人可以告诉我如何获得如下结果。
使用 rank
我也希望得到“total_offer”,它应该是“offer1”和“offer2”的总和。当没有 offer2(例如:taurus)时,'total offer' 应该是 'offer1' 和 'null' for 'offer2'
输入:
customer make zipcode offer notes
mark focus 101 250 cash
mark focus 101 2500 appreciation cash
mark focus 101 1000 cash
mark focus 101 1500 cash offer
henry 520i 21405 500 cash offer
henry 520i 21405 100 cash
henry 520i 21405 750 appreciation cash
henry 520i 21405 100 cash
mark taurus 48360 250 appreciation cash
mark mustang 730 500 cash
mark mustang 730 1000 Cash offer
mark mustang 730 1250 appreciation cash
期望的输出:
| CUSTOMER | MAKE | ZIPCODE | TOP_OFFER1 | notes1 | TOP_OFFER2 | notes2 | Total_offer |
| henry | 520i | 21405 | 750 | appreciation cash | 500 | cash offer | 1250
| mark | focus | 101 2500 | appreciation cash | 1500 | cash offer | 4000
| mark | mustang | 730 | 1250 | appreciation cash | 1000 | cash offer | 2250
| mark | taurus | 48360 | 250 | appreciation cash | NULL | 250 |
谢谢
PS:
下面的链接告诉我需要执行dense_rank 才能获得前2 名的优惠。 (Using a pl-sql procedure or cursor to select top 3 rank)
【问题讨论】:
标签: sql oracle stored-procedures oracle11g cursor