Packages' licenses are described in /usr/share/doc/${package}/copyright. This file is required to specify the main license of the package; many packages use a machine-readable copyright file which lists the licenses of every single file in the source package.
For machine-readable files, you can use the License: line which introduces licenses:
awk '/^License:/ { print $2 }' /usr/share/doc/*/copyright | sort -u
If you're looking for a license documented in /usr/share/common-licenses, you can look for mentions of those in the copyright files; e.g. to count the number of packages licensed under the GPL or LGPL:
grep -l GPL /usr/share/doc/*/copyright | wc -l
To only count the number of source packages, count the number of unique files (binary packages shipped from a single source package have the exact same copyright file, or link to the same file):
md5sum $(grep -l GPL /usr/share/doc/*/copyright) | sort -k1,1 -u | wc -l
Debsources provides various ways of searching through all of Debian's copyright files; here's a one-liner to retrieve the license of a single file (if its package uses a machine-readable format). (The license of that one-liner isn't documented, so I'm just linking to it, not copying it here.)
Note that since the copyright files document the licenses of the source packages, they may well document files which aren't shipped in binary packages and don't affect the license of the binary package; this can be the case for example with GPL-licensed files which are only used during the build for a non-GPL-licensed package.