-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeedingoutQueries.sql~
36 lines (26 loc) · 1.41 KB
/
WeedingoutQueries.sql~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Following query returns the total number of Books in Delhi Library
SELECT count(1) FROM items WHERE items.itype='BK' AND items.homebranch = 'DL';
-- It gives all the books at Delhi Library which have never been checked out
-- Items are sorted by Item accession date in descending order
SELECT items.barcode, biblio.title, biblio.author, items.dateaccessioned
FROM items
LEFT JOIN biblio ON (items.biblionumber = biblio.biblionumber)
LEFT JOIN issues ON (items.itemnumber = issues.itemnumber)
LEFT JOIN old_issues ON (items.itemnumber = old_issues.itemnumber)
WHERE items.itype = 'BK'
AND items.homebranch = 'DL'
AND (issues.itemnumber IS NULL AND old_issues.itemnumber IS NULL)
GROUP BY items.itemnumber -- Select only distinct
ORDER BY items.dateaccessioned DESC;
-- Following query returns all the items of particular Category and belonging to
-- particular Library which have been issued at least once
SELECT items.barcode, biblio.title, biblio.author, items.dateaccessioned
FROM items
LEFT JOIN biblio ON (items.biblionumber = biblio.biblionumber)
LEFT JOIN issues ON (items.itemnumber = issues.itemnumber)
LEFT JOIN old_issues ON (items.itemnumber = old_issues.itemnumber)
WHERE items.itype = 'BK'
AND items.homebranch = 'DL'
AND (issues.itemnumber IS NOT NULL OR old_issues.itemnumber IS NOT NULL)
GROUP BY items.itemnumber -- Select only distinct
ORDER BY items.dateaccessioned DESC;