Fix min/max queries in SQL trafic.