Syntax:
SELECT Id, UserName FROM User WHERE Id IN ( SELECT AssigneeId FROM PermissionSetLicenseAssign WHERE PermissionSetLicense.MasterLabel = ‘<Name of the Permission Set License’ )
You can get the Name of the Permission Set License from Company Information.
Sample:
SELECT Id, UserName FROM User WHERE Id IN ( SELECT AssigneeId FROM PermissionSetLicenseAssign WHERE PermissionSetLicense.MasterLabel = ‘Messaging User’ )
The above query returns all the users who have Messaging User Permission Set License.