sql select distinct values and count of each