Hi.
Can anyone explain what’s going on here please?
The first query results in two rows, each with CIP=1.
The second query is supposed to add these together, and gives the answer 4.
If either of the values is zero, the sum correctly comes out as 1.
I’ve investigated this a bit further, and it’s clear that the outer SELECT is
producing results which don’t come from the inner SELECT. I have no idea how
that’s possible.
Here’s the inner SELECT, with all fields selected:
select * from mqtt_consumer where(topic=‘Live’) and cluster!=‘’ and CIP>0
group by cluster order by time desc limit 1
name: mqtt_consumer
tags: cluster=krypton
time CIP callid host server topic
1558008970624610278 1 1558008953 systemy iodine Live
name: mqtt_consumer
tags: cluster=argon
time CIP callid host server topic
1558008183447539177 1 1558008117 systemy copper Live
Now surround this with an outer SELECT, also for all fields, and a new result
pops up:
select * from (select * from mqtt_consumer where(topic=‘Live’) and
cluster!=‘’ and CIP>0 group by cluster order by time desc limit 1) order by
time desc
name: mqtt_consumer
time CIP callid cluster host server topic
1558008970624610278 1 1558008953 krypton systemy iodine Live
1558008183447539177 1 1558008117 argon systemy copper Live
1557667706170163858 1 3 krypton systemy iodine Live
Can someone tell me:
a) what’s going on here - how can an outer SELECT return more results than the
inner one?
b) how can I re-phrase my query so that I can get the sum of the two values
of CIP returned from the inner select?
What I’m aiming for is the sum of the most recent value of “CIP” returned for
each value of “cluster”.
Thanks,
Antony.