[Koha] SQL for items with a lot of holds
Ian Walls
ian.walls at bywatersolutions.com
Fri Jul 1 15:14:50 NZST 2011
Cindy,
You may also want to try changing
> WHERE items.ccode = 'BK%'
...to...
WHERE items.ccode LIKE 'BK%'
...if you're trying to match on any ccode starting with "BK"
Also, I'm not sure if your ILS has this or not, but in Koha 3.2 and above
there is a neat feature in Reports called Runtime Parameters. You can add a
place-holder for things like item type or collection code, and rather than
specifying them directly in the report, you'll be prompted to add the
limitation (or pick from a dropdown) when you run the report. This can
greatly consolidate the number of reports you need to save, and provide
consistency in output (though, with Koha 3.4 and greater, you have filters
on the reports list so you can find which ones you need without scrolling
through the complete list).
Cheers,
-Ian
On Thu, Jun 30, 2011 at 11:01 PM, Chris Cormack <chris at bigballofwax.co.nz>wrote:
> On 29 June 2011 10:24, Cindy Weber <cweber at scls.lib.wi.us> wrote:
> > I'm trying to write a report that will list items with the number of
> > holds/items over a certain number and then list the number of holds
> > placed per library. Since the holds to items ratio is different
> > depending on the format of the item (book, DVD, CD, etc.) I'm thinking
> > I've got to have one report for each item type.
> >
> > My initial attempt:
> > SELECT biblio.biblionumber, reserves.branchcode AS 'Library',
> > biblio.title AS 'Title', COUNT(items.biblionumber) AS 'Copies',
> > COUNT(reserves.biblionumber) AS 'Holds'
> > FROM biblio
> > LEFT JOIN items ON (items.biblionumber = biblio.biblionumber)
> > LEFT JOIN reserves ON (reserves.biblionumber = items.biblionumber)
> > LEFT JOIN biblioitems ON (biblioitems.biblionumber = biblio.biblionumber)
> > WHERE items.ccode = 'BK%'
> > GROUP BY biblio.biblionumber HAVING
> > (COUNT(reserves.biblionumber)/COUNT(items.biblionumber)) > 15
> >
> >
> > When trying to troubleshoot why this didn't return any results, I
> > discovered that
> > SELECT biblio.title, COUNT(items.biblionumber),
> COUNT(reserves.biblionumber)
> > FROM biblio
> > JOIN items ON (items.biblionumber = biblio.biblionumber)
> > JOIN reserves ON (reserves.biblionumber = biblio.biblionumber)
> >
> > returned really large numbers and the items and holds numbers wer all
> > equal. For a specific bibionumber, it gave me 520 for both the count of
> > items and the count of reserves. There are 8 holds and 65 items for
> > that biblionumber. So it's multiplying the two counts together and
> > returning that as the result. Changing the JOIN types didn't help any.
> > Can anyone please tell me what I'm doing wrong and how to fix this?
> >
> Hi Cindy
>
> We can try, but since you aren't running an official release of Koha,
> we can only guess at your database structure. What you probably want
> to do, is group the results by biblionumber. You are trying to find
> out the number of reserves, and the number of items for each
> biblionumber right?
>
> Chris
> _______________________________________________
> Koha mailing list http://koha-community.org
> Koha at lists.katipo.co.nz
> http://lists.katipo.co.nz/mailman/listinfo/koha
>
--
Ian Walls
Lead Development Specialist
ByWater Solutions
ALA Booth 732
Phone # (888) 900-8944
http://bywatersolutions.com
ian.walls at bywatersolutions.com
Twitter: @sekjal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.katipo.co.nz/pipermail/koha/attachments/20110630/ea04c86f/attachment.htm
More information about the Koha
mailing list