This topic is locked
[SOLVED]

 Add to fields to make a new field

10/29/2019 7:10:11 PM
PHPRunner General questions
gehrenfeld author

I have this query and I want to add hour1 + hour2 = thour

Not sure how to do that with AS variables
SELECT

start1,

start2,

stop1,

stop2,

miles,

other,

CONCAT(MOD(HOUR(TIMEDIFF(stop1,start1)), 24)) AS hour1,

CONCAT(MOD(HOUR(TIMEDIFF(stop2,start2)), 24)) AS hour2

FROM daily
Thanks for the help

M
Mark Kramer 10/30/2019



I have this query and I want to add hour1 + hour2 = thour

Not sure how to do that with AS variables
SELECT

start1,

start2,

stop1,

stop2,

miles,

other,

CONCAT(MOD(HOUR(TIMEDIFF(stop1,start1)), 24)) AS hour1,

CONCAT(MOD(HOUR(TIMEDIFF(stop2,start2)), 24)) AS hour2

FROM daily
Thanks for the help


Check Here for inspiration https://stackoverflow.com/questions/15149775/how-to-add-results-of-two-select-commands-in-same-query

gehrenfeld author 10/30/2019

Sorry I didn't make it more clear.
both the hour1 and hour2 are in the same database table. I was looking for a way to add the SQL statement to the current script that I posted.
Sorry for not being more clear.

Sergey Kornilov admin 10/30/2019

Try this:

SELECT

start1,

start2,

stop1,

stop2,

miles,

other,

CONCAT(MOD(HOUR(TIMEDIFF(stop1,start1)), 24)) AS hour1,

CONCAT(MOD(HOUR(TIMEDIFF(stop2,start2)), 24)) AS hour2,

CONCAT(MOD(HOUR(TIMEDIFF(stop1,start1)), 24)) + CONCAT(MOD(HOUR(TIMEDIFF(stop2,start2)), 24)) AS thour

FROM daily