MySQL Compare between 2 Tables then add results -


i have table next structure

table a:

| id  |   1     |     2    |     3     | |-----|---------|----------|-----------| |   1 | 00:05:00| 00:10:00 | (null)    | |   2 | 00:10:00|  (null)  | (null)    | 

table b

| id  |   col   |expected  | |-----|---------|----------| |   1 |     1   | 00:06:00 | |   2 |     2   | 00:12:00 | |   3 |     3   | 00:22:00 | 

i trying make sum depending on actual value on rows of table in comparison expected on table b

select      id, (select ??????? (select tiempostd b)as stime) time    

basically want make comparison between 2 tables see 1 greater , add next one.

i cant manage understand how call specific value under temp table stime.

i not familiar sql thats why cant this, logic this. in question marks on query

addtime(if(a.1>(stime.expected col = 1),a.1,(stime.expected col = 1)), addtime(if(a.2>(stime.expected col = 2),a.2,(stime.expected col = 2)), if(a.3>(stime.expected col = 3),a.3,(stime.expected col = 3)) 

stime.expected col = 3 bad syntax right? hope point of logic im trying make here.

so output this

| id  |   time  | |-----|---------| |   1 | 00:40:00| |   2 | 00:44:00| 

use union convert table a table separate rows each column, join table b.

select * tableb b join (select id, 1 col, a.1 time       tablea       union        select id, 2 col, a.2 time       tablea       union        select id, 3 col, a.3 time       tablea a) on a.id = b.id , a.col = b.col 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -