Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Kysely järjestää tulokset borrowernumberin (=asiakas-id), viimeksi nähdyn pvm ja päivityspvm mukaan. 

SELECT DISTINCT borrowers.borrowernumber, borrowers.surname, borrowers.firstname, borrowers.cardnumber, borrowers.categorycode, borrowers.dateenrolled, borrowers.lastseen, borrowers.updated_on, borrowers.debarred

FROM borrowers

WHERE NOT EXISTS (SELECT borrowernumber FROM statistics WHERE borrowers.borrowernumber = borrowernumber AND statistics.datetime >= '2020-10-15')

and categorycode in ('KOT', 'ERI', 'LUK')

and borrowernumber not in

  ( select borrowernumber from issues )

and borrowernumber not in

    (select borrowernumber from reserves)

and borrowernumber not in

  ( select borrowernumber

    from accountlines

    where amountoutstanding > 0 )

and dateenrolled < '2020-10-15'

and lastseen < '2020-10-15'

and updated_on < '2020-10-15'

and debarred IS NULL

order by borrowernumber, lastseen, updated_on

...