lundi 28 septembre 2015

MYSQL group by query

i have following table in my MYSQL database

busnames

id |busname

routes

id|route_name

timings table

id | bus_id | route_id | trip |direction |bus_time

  • one bus contain many trips per day
  • each trip contain 2 direction (0|1)
  • 0 means source to destination

  • 1 means destination to source

Now i want to dispaly data group by trip where bus_id="some_id" and for each page per trip data .if i click next then i need to show second trip data

BusRouteName |Trip | Departure (0)| Destination(1)|

Newyork        1         8 a.m       10.am

i have tried many queries in mysql but it doesn't seems to produce correct output

SELECT * FROM timings t inner join routes r on t.route_id=r.id inner join busnames b on t.bus_id=b.id where b.id=1

Can any one tell how i can get the data based on trip ? thank you

Aucun commentaire:

Enregistrer un commentaire