mysql - TIMEDIFF Subquery returns more than 1 row in mariadb -


having issue specific section of query using timediff , addtime:

i want result :

| waktuhilang | |-------------| |    04:00:00 | |    03:00:00 |  select addtime(     (         select             sec_to_time(                 sum(                     time_to_sec(                         maketime(                             durasi + 0,                             substring_index(durasi, 'jam ', - 1) + 0,                             0                         )                     )                 )             ) waktudw                     trans_lhpdtdw     ),     (         select             timediff(jammasuk, jammulai) lamaistirahat                     trans_lhphd     ) ) waktuhilang 

i've seen people mentioning using in instead of = within subquery, can't seem work. ideas out there? thanks

i have 2 tables :

table trans_lhpdtdw table trans_lhphd

create table `trans_lhpdtdw` (   `idbukti` int(11) not null,   `partid` varchar(50) not null,   `typedowntime` varchar(50) not null,   `durasi` varchar(50) not null,   `keterangandowntime` longtext not null  ) engine=innodb default charset=latin1;  -- ---------------------------- -- records of trans_lhpdtdw -- ---------------------------- insert `trans_lhpdtdw` values ('2', 'blap-fg150-kt-kgx', 'setting mold', '1 jam 0 menit', 'ass'); insert `trans_lhpdtdw` values ('1', 'blap-fg152-pf-kgx', 'tidak ada fasilitas', '1 jam 0 menit', 'as'); insert `trans_lhpdtdw` values ('1', 'awdx-fg002-hn-kgx', 'tidak ada job', '2 jam 0 menit', 'sasa');  create table `trans_lhphd` (   `idbukti` int(11) not null auto_increment,   `nobukti` varchar(1000) not null,   `periode` int(6) not null,   `tanggal` date not null,   `divisi` varchar(50) not null,   `jamkerja` varchar(10) not null,   `jamproduksi` time not null,   `jamselesai` time not null,   `jammulai` time not null,   `jammasuk` time not null,   `idmesin` varchar(50) not null,   `lineid` varchar(50) not null,   `operator` int(5) not null,   `planning` decimal(18,0) not null,   `tambahan` varchar(50) default null,   primary key (`idbukti`),   key `idbukti` (`idbukti`),   key `idbukti_2` (`idbukti`) ) engine=innodb auto_increment=3 default charset=latin1;  -- ---------------------------- -- records of trans_lhphd -- ---------------------------- insert `trans_lhphd` values ('1', 'lhp/201708/00001', '201708', '2017-08-24', 'all divisi import (non ppic)', 'shift i', '01:05:00', '09:05:00', '01:00:00', '02:00:00', 'bh 260k', 'l3002', '1', '213', '1 jam 15 menit'); insert `trans_lhphd` values ('2', 'lhp/201708/00002', '201708', '2017-08-17', 'injection', 'shift i', '07:00:00', '16:00:00', '11:25:00', '13:25:00', 'bh 260k', 'l2002', '100', '1000', ''); 

an approach providing 1 row each idbukti

query:

select    d.idbukti, addtime(w.waktudw, timediff(d.jammasuk, d.jammulai)) waktuhilang trans_lhphd d inner join (            select idbukti, sec_to_time(sum(time_to_sec(maketime(durasi + 0, substring_index(durasi, 'jam ', - 1) + 0, 0)))) waktudw            trans_lhpdtdw            group idbukti            ) w on d.idbukti = w.idbukti 

results:

| idbukti | waktuhilang | |---------|-------------| |       1 |    04:00:00 | |       2 |    03:00:00 | 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -