数据库多条记录去重问题

我有一张日志表,里面的用户每天登录多次可能出现多条数据,用户每天登录多次算一次,我现在要查询一段时间内,登录过的用户和该用户登录过的次数,怎么写SQl语句

这是表图片说明

select count(用户id) from 表名 where 条件 group by 用户id

select userId,count(1) from userLogin group by userId where loginTime >'2016-03-01' and loginTime <'2016-03-17'

select date_id,count(ip),count(distinct ip) from log group by ip,dateId

select t.name, count(*) from reg_opt t where t.create_time between to_date('2015-01-01','RRRR-MM-DD') and to_date('2016-05-01', 'RRRR-MM-DD') group by t.name

select distinct column_name from table where condition

select id,count(id) from (select distinct id, convert(date,date_time) as date_time from table)a group by id

看了一下回答,貌似都只说了怎么删除。其实我觉得应该在源头解决问题:在save数据的时候先查询,如果没有就new 一个,这样可以确保数据的唯一性。