想要在Sql中采用两列的区别 [英] Want to take the difference of two columns in Sql
本文介绍了想要在Sql中采用两列的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想采用表格中各列的区别.我们将列名命名为Planned_date,所以现在我要采用这两列的区别.
I want to take the difference of columns of a table.we have column name as Planned_date so now I Want to take the difference of these two columns
A = Planned_Date of stop1 - Planned_Date of stop5
那么我该如何编写查询以获取A的值 下面是我编写的示例查询,但是以某种方式对我不起作用.
So how I can write the query to fetch the value of A below is the sample query I have written but somehow it is not working for me.
select (select planned_arrival as val1
from shipment_stop
where stop_num = 1
and shipment_gid = 'IFFCO/LOGISTICS.L171009358')
-
(select planned_arrival as val2
from shipment_stop
where stop_num = 5
and shipment_gid = 'IFFCO/LOGISTICS.L171009358')
请帮助.
推荐答案
尝试一下-
SELECT
s1.planned_arrival - s2.planned_arrival AS val
FROM
shipment_stop s1,
shipment_stop s2
WHERE
s1.stop_num = 1
AND s2.stop_num = 5
AND s1.shipment_gid = 'IFFCO/LOGISTICS.L171009358'
AND s1.shipment_gid = s2.shipment_gid;
这篇关于想要在Sql中采用两列的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文