简体   繁体   English

设置列值等于columnB减去columnA

[英]set column values equals to columnB minus columnA

I want my MySql Column 'Time' to be update as Column 'End_Time' Minus Column 'Start_Time' 我希望将MySql列“时间”更新为列“ End_Time” 减去列“ Start_Time”

Note: End_Time & Start_Time are in DATETIME format.... 注意:End_Time和Start_Time为DATETIME格式。

Thanks 谢谢

Try this method, 试试这个方法

SELECT SEC_TO_TIME(TIMESTAMPDIFF(second,Start_Time,End_Time)) --include sec
or
SELECT SEC_TO_TIME(TIMESTAMPDIFF(minute,Start_Time,End_Time)*60) --diff in minute

eg

SELECT SEC_TO_TIME(TIMESTAMPDIFF(minute,'2016-05-04 10:00:00','2016-05-04 11:29:00')*60)

Here TIMESTAMPDIFF(minute will return the diff in minutes and mutiple it *60 to get seconds, and use SEC_TO_TIME to convert from sec to Time. 在这里TIMESTAMPDIFF(minute将返回以分钟为单位的差异,并将其乘以* 60以获得秒,并使用SEC_TO_TIME将秒转换为时间。

Use Datediff function in mysql 在MySQL中使用Datediff函数

See here for DATEDIFF 看到这里DATEDIFF

you can use TIMESTAMPDIFF function. 您可以使用TIMESTAMPDIFF函数。

SELECT TIMESTAMPDIFF(minute, '2015-06-01 13:13:55', '2015-06-03 10:15:20')

SELECT TIMESTAMPDIFF(second, '2015-06-01 13:13:55', '2015-06-03 10:15:20')

SELECT TIMESTAMPDIFF(hour, '2015-06-01 13:13:55', '2015-06-03 10:15:20')
update table 
set Time = (select 
            to_timestamp(End_Time,'yyyy-mm-dd hh24:mi:ss') - to_timestamp(Start_Time,'yyyy-mm-dd hh24:mi:ss')
            );

暂无
暂无

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

相关问题 mysql-通过columnB中的值显示columnA中的值 - mysql - displaying values from columnA by values in columnB 选择不同的值ColumnA,而ColumnB = Value1和ColumnB = Value2 - Select Distinct values ColumnA while ColumnB = Value1 and ColumnB = Value2 PHP/MySQL - SELECT 和 SUM Distinct GROUP BY ColumnA WHERE columnB =? AND 列 C =?。 最好的方法是什么? - PHP/MySQL - SELECT and SUM Distinct GROUP BY ColumnA WHERE columnB = ? AND Column C = ?. What is the best method for this? 查询一个不同的值,其中columnA!= columnB - Query a distinct value where a columnA != columnB 如何查找包含columnA和columnB的所有表 - How to find all tables that contain columnA and columnB SQL 如何 select columnA 和 columnB 其中 columnB 具有不同的值 - SQL How to select columnA and columnB where columnB has a distinct value 用sum(cloumnC)选择不同的columnA和columnB - select distinct columnA and columnB with sum(cloumnC) 仅保留 SQL 中的行,其中 columnA 中的值大于 columnA 中的值,并且 columnB 中的值等于 x 没有嵌套问题 - Only keep rows in SQL where the value in columnA is bigger than the value in columnA and the value in columnB is equal to x without a nested question 选择columnA具有多个唯一的columnB值的行 - Select rows where columnA has more than one unique columnB value 如何在sql中比较同一表的第一条记录中的列A和第二条记录中的列B - How to compare columnA in 1st record and columnB in 2nd record of a same table in sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM