Before digging into the belly of the beast (database)… have you already checked if the difference could be based on collections? Plex only shows the number of items – not files. If your library is hiding items which are part of a collection, this could explain the gap.
In order to verify, simply sort your library by anything but by title.
If that doesn’t explain the difference in numbers – check out Export Tools from the WebTools-NG package.