SELECT stable.scate, stable.stname, s2table.aTime, atable.stname, a2table.aTime, available_reservation_seat AS ars, if( stable.scate = 'KTX', 7200 * count( 2table.no ) +8400, if( stable.scate = '새마을', 3136 * count( 2table.no ) +4800, 950 * count( 2table.no ) +2600 ) ) * rtable.ea as fee
FROM 1table AS stable, 1table AS atable, 2table AS s2table, 2table AS a2table, 2table, 3table, rtable
WHERE stable.stname = rtable.sStion
AND atable.stname = rtable.aStion
AND stable.scate = atable.scate
AND stable.no = s2table.t1no
AND atable.no = a2table.t1no
AND s2table.tno = a2table.tno
AND s2table.aTime >= rtable.Time
AND 2table.no > s2table.no
AND 2table.no < a2table.no
AND s2table.no = 3table.t2no
AND 3table.dynamic_date > ( rtable.date - curdate( ) )
Group by s2table.no