现在有A、B两个表,两个表通过up_location和DIS_location两个字段进行连接匹配。要计算price*CA*A+price*CB*B.....+price*CZ*Z的每一行的和。这里面要注意日期,dep_location如果不在st_date和end_date范围内的行不要,如果在时间范围内但是匹配到的A,B,C到Z为空值时,则用up_location和dis_location为***那一行中相对应的A,B,C到Z的值。这个select的语句怎么写。求大神指教。
select b.price*b.CA*(case a.A when null then selelct A from A where up_location=*** and
dis_location=*** else a.A)+b.price*b.CB*a.B.....+price*CZ*Z from A a,B b
where a.up_location=b. up_location and a.DIS_location=b. DIS_location
and b.up_location>a.st_date and b.up_location<a.end_date
B C D ...按照这个例子就好了 希望能帮到你
select b.price*b.CA*(case a.A when null then selelct c.A from A c where up_location="***" and
dis_location=*** else a.A end) from A a,B b
where a.up_location=b. up_location and a.DIS_location=b. DIS_location
and b.up_location>a.st_date and b.up_location<a.end_date