Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql视图与jdbc选择联接,在哪里进行抽象?_Sql_Stored Procedures_Jdbc_Abstraction_Sql View - Fatal编程技术网

Sql视图与jdbc选择联接,在哪里进行抽象?

Sql视图与jdbc选择联接,在哪里进行抽象?,sql,stored-procedures,jdbc,abstraction,sql-view,Sql,Stored Procedures,Jdbc,Abstraction,Sql View,我有3个表(见下文),表A描述了一种产品,表B保存了不同日期的库存信息,表C保存了不同日期的每个产品的价格 Table A ------------------ product_id product_name 1 book 2 pencil 3 stapler ... ... Table B ------------------ product_id date_id

我有3个表(见下文),
表A
描述了一种产品,
表B
保存了不同日期的库存信息,
表C
保存了不同日期的每个产品的价格

 Table A
 ------------------
 product_id    product_name
 1             book
 2             pencil
 3             stapler
 ...           ...

 Table B
 ------------------
 product_id    date_id     quantity
 1             2012-12-01  100
 1             2012-12-02  110
 1             2012-12-03  90
 2             2012-12-01  98
 2             2012-12-02  50
 ...           ...         ...

 Table C
 -------------------
 product_id   date_id      price
 1            2012-12-01   10.29
 1            2012-12-02   12.12
 2            2012-12-02   32.98
 3            2012-12-01   10.12
在我的java应用程序的许多部分中,我想知道每个产品的美元价值是多少,因此我最终执行以下查询

 select 
      a.product_name,
      b.date_id,
      b.quantity * c.price as total
 from A a
 join B b on a.product_id = b.product_id
 join C c on a.product_id = c.product_id and b.date_id = c.date_id
 where b.date_id = ${date_input}
今天我有一个想法,我可以让上面的查询成为一个视图(减去日期条件),然后查询特定日期的视图,这样我的查询看起来就像

 select * from view where date_id = ${date_input}
我不确定这种逻辑的适当抽象级别在哪里。它应该是java代码(从pref文件读取)还是编码到数据库中的视图中


我不想把它作为一个视图的唯一原因是,随着时间的推移,加入将变得昂贵,因为将有越来越多的日期要覆盖,我通常只对过去一个月的数据值感兴趣。也许存储过程更好?这是一个抽象这种逻辑的好地方吗?

如果视图实现正确,在这种情况下,如果没有视图,查询将是相同的,那么您永远不会看到最差的性能。更多日期不会影响性能,因为您有此视图

在这种情况下,创建视图是正确的抽象