S
S
Sland Show2018-10-23 17:52:58
MySQL
Sland Show, 2018-10-23 17:52:58

How to fix data sampling by time?

I have two fields in a table of type timestamp : date_departure and date_arrival .

And there is a corresponding QHL (I think that you can understand it in SQL) query for selecting data.

If my user entered the date_departure input field and did not enter date_arrival, then I call the first DAO functionality. If the user entered both fields - the second one.

I have:

1st

public List<Schedule> getByStationsViaDate(Schedule schedule) {
        return sessionFactory.getCurrentSession()
                .createQuery("from Schedule where " +
                        "stationArrival = :stationArrival and " +
                        "stationDeparture = :stationDeparture and " +
                        "dateDeparture > :dateDeparture " +
                        "order by dateDeparture desc ")
                .setParameter("stationArrival", schedule.getStationArrival())
                .setParameter("stationDeparture", schedule.getStationDeparture())
                .setParameter("dateDeparture", schedule.getDateDeparture())
                .getResultList();
    }


2nd:

public List<Schedule> getByStationsViaDates(Schedule schedule) {
        return sessionFactory.getCurrentSession()
                .createQuery("from Schedule where " +
                        "stationArrival = :stationArrival and " +
                        "stationDeparture = :stationDeparture and " +
                        "dateDeparture > :dateDeparture and " +
                        "dateArrival < :dateArrival " +
                        "order by dateDeparture desc ")
                .setParameter("stationArrival", schedule.getStationArrival())
                .setParameter("stationDeparture", schedule.getStationDeparture())
                .setParameter("dateDeparture", schedule.getDateDeparture())
                .setParameter("dateArrival", schedule.getDateArrival())
                .getResultList();
    }



How can I fix the query so that in the first case the data is pulled by the departure date?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question