每日一题-92(净现值查询)

题92:

根据下面两表写一个 SQL, 找到 Queries 表中每一次查询的净现值。
每日一题-92(净现值查询)
其中:

  • NPV表:id, year 是该表主键,该表有每一笔存货的年份, id 和对应净现值的信息;
  • Queries表:id, year 是该表主键,该表有每一次查询所对应存货的 id 和年份的信息。

解题思路:此题需要注意的是Queries 表中有些在NPV 表中没有匹配的npv为null,用ifnull判断,连接两表即可。

select q.id,q.year,ifnull(npv,0) npv   
from Queries q 
left join NPV n on q.id = n.id and q.year = n.year;
上一篇:UnboundLocalError: local variable 'range' referenced before assignment


下一篇:python类和继承