Hello, it's been years since I've dazzled in sql.I get an issue when trying to create my sub query. Something to do with my group by. Anyway I've gotten nowhere after 2 days. Hope someone can help.
So I have two tables.
access_points
Fieldname: id
Fieldname: name
Fieldname: mac_address
Fieldname: product
Fieldname: tower_id
Fieldname: type
Fieldname: created_at
Fieldname: updated_at
Fieldname: ip_address
Fieldname: tag
Fieldname: isActive
access_point_statistics
Fieldname: id
Fieldname: access_point_id
Fieldname: mode
Fieldname: dl_retransmit
Fieldname: dl_retransmit_pcts
Fieldname: dl_pkts
Fieldname: ul_pkts
Fieldname: dl_throughput
Fieldname: ul_throughput
Fieldname: status
Fieldname: connected_sms
Fieldname: reboot
Fieldname: dl_capacity_throughput
Fieldname: created_at
Fieldname: updated_at
Fieldname: lan_speed_status
OK I would like the access_point_id, the MAX (dl_throughput) and the AVG(connected_sms) from table 2 where created_at is between $start_date and $end_date. I also require the name from table 1 and to join both tables would be the id from table 1 with the access_point_id from table 2.
This is what i have so far.. but I get GROUP BY error.
select
ap.name,
a.access_point_id,
a.max,
a.avg
from
access_points ap
inner join (
select
aps.access_point_id,
max(aps.dl_throughput) as max,
avg(aps.connected_sms) as avg
from
access_point_statistics aps
where
aps.created_at BETWEEN '$start_time%' and '$end_time%'
group by
1) a
on ap.id = a.access_point_id