简体   繁体   English

如何计算Sql Developer中两个不同列的月差?

[英]how to calculate month difference from two different columns in Sql Developer?

I want to calculate month difference in same table from 2 different columns.我想从 2 个不同的列计算同一个表中的月差。 In other words, I have 2 different columns that include dates and I would like to see their month difference in Sql Developer.换句话说,我有 2 个包含日期的不同列,我想在 Sql Developer 中查看它们的月份差异。 Is there any way to do that?有没有办法做到这一点?

Thank you.谢谢你。

for mysql : The DATEDIFF function can give you the number of days between two dates.对于 mysql : DATEDIFF函数可以为您提供两个日期之间的天数。

for oracle: months_between甲骨文: months_between

sample:样本:

SELECT months_between(column1,column2)
FROM Table

for the month differnce the standard sql is DATEDIFF, in this function you must pass 3 params, if you must calculate the difference from 2 columns, c1 and c2, you must do this query对于月差,标准 sql 是 DATEDIFF,在此函数中,您必须传递 3 个参数,如果必须计算 2 列 c1 和 c2 的差,则必须执行此查询

SELECT DATEDIFF(month,c1 , c2)
FROM T
WHERE ...

Here the documentation of datediff https://www.w3schools.com/sql/func_sqlserver_datediff.asp这里是 datediff https://www.w3schools.com/sql/func_sqlserver_datediff.asp的文档

if you use oracle you can use also如果你使用 oracle 你也可以使用

SELECT months_between(c1,c2)
FROM T
WHERE ...

This is the documentation https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions089.htm这是文档https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions089.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM