如何解决如何从sql中的不同表中获取两个不同日期之间的天数?
我需要估计不同表格中 2 个不同日期之间的天数。
我曾尝试使用 datediff
函数,但没有奏效。
这是我试过的查询:
select
t1."group",datediff(t2.start_date,t1.event_date),count(distinct t1.employee_id)
from t1 join t2 on t1.project_id = t2.id
where true
and t1.cummulative_manhour > 0
and t1.company_id in ('a','b')
and t1.event_date = '2021-05-17'
and t1.project_id = '2900'
group by
t1."group",t2.start_date,t1.event_date
错误信息说:
SQL Error [42883]: ERROR: function datediff(date,date) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 29
我使用的数据库是 postgresql。
我应该如何编写查询以获得预期的天数?
提前致谢。
解决方法
如错误消息所示,Postgres 不支持 -
。相反,它只使用 (t2.start_date - t1.event_date),
:
let offset = this.currentPage * this.gridperPage
let accToken = localStorage && localStorage.loggedinUser ? localStorage.loggedinUser : null;
const categoryUrl = project_key + `/product-projections/search?offset=${offset}&limit=${this.gridperPage}`;
const sendGetRequest = async() => {
let access_token = await axios.request({
method: "get",baseURL: categoryUrl,headers: {
'Authorization': "Bearer " + accToken,'Content-Type': 'application/json',},data: {}
}).then((response) => {
if (response) {
// this.productsList = response.body;
this.productsList = response.data.results;
// eslint-disable-next-line
console.log(this.productsList);
}
});
};
sendGetRequest();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。