我有以下查询。
select a.nume_echipament,
a.producator,
a.seria,
b.uc,
b.port,
(select starea from echipamente order by data desc, ora desc limit 1) as starea,
a.durata_aprovizionare,
a.durata_viata,
( select data_aprov from aprovizionari where nume_echipament='automat_imbuteliere' order by date(data_aprov) desc, time(ora_aprov) desc limit 1) as data_aprov,
( select ora_aprov from aprovizionari where nume_echipament='automat_imbuteliere' order by date(data_aprov) desc, time(ora_aprov) desc limit 1) as ora_aprov,
sec_to_time(count(starea)*5) as durata_totala
from date_tehnice a
inner join echipamente b on a.nume_echipament=b.nume_echipament
inner join aprovizionari c on c.nume_echipament=a.nume_echipament
where a.nume_echipament='automat_imbuteliere'
and
b.starea='1'
and
b.data > c.data_aprov
and
b.ora >c.ora_aprov
;
问题是它取两次行。它会影响我的'durata_totala'(总生命期)变量,因为我没有得到例如00:00:05,而是00:00:10。 我有一个表,其中'1'表示设备打开,否则为0。 这就是为什么我有数(starea * 5)。因为我的arduino每5秒向数据库发送一次数据。
有人可以帮我解决问题吗?