shopkeeper
表格包含以下字段:
id (bigint),amount (numeric(19,2)),createddate (timestamp)
比方说,我有上表.我想要昨天的记录,还有 通过将金额打印到美分来生成报告.
One way of doing is to perform calculations in my java application and execute a simple query个
Date previousDate ;// $1 calculate in application
Date todayDate;// $2 calculate in application
select amount where createddate between $1 and $2
然后遍历记录,在我的java应用程序中将金额转换为美分并生成报告.
Another way is like performing calculations in sql query itself:
select cast(amount * 100 as int) as "Cents"
from shopkeeper where createddate between date_trunc('day', now()) - interval '1 day' and date_trunc('day', now())
然后遍历记录并生成报告
在某种程度上,我的所有处理都是在Java应用程序中完成的,并触发一个简单的查询. 在其他情况下,所有转换和计算都在SQL查询中完成.
上面的用例只是一个例子,在实际场景中,一个表可以有许多需要类似处理的列.
Can you please tell me which approach is better in terms of performance and other aspects and why?