select * from 用户表 where 用户名 in (select 用户名 from 用户表 group by 用户名 having count(1)>1)
inner join 会兼顾两张表,应该是你另一个表里面那个主键的数据有两条;;;先确定主表,用left join 或者right join 就会只有一条了
selectt1.id,t1.from_uid,t2.name as from_name,t1.to_uid,t3.name as to_name,t1.contentfromchat t1,user t2,user t3where 1=1and t1.from_uid = t2.idand t1.to_uid = t3.idand t2.name in ('张三', '李四')and t3.name in ('张三', '李四')...
上面的回答可以,不过我觉得还有更简单的方法: select aid, count(distinct uid) from 表名 group by aid 这是sqlserver 的写法。。。
两种方法,一种是查询重复的数据,只查询重复记录,不管其余信息,如ID什么的: select uid, time from ztest GROUP BY uid, time having count(*)>1;查出结果是 uid time 1 1 还有一种是查询你指定信息,可以查询出ID信息: select distinct a....
看一下这个SQL selectsum(if((sex = 1 and age = 2),1,0)),sum(if((sex = 1 and age = 5),1,0)),sum(if((sex = 1 and age = 10),1,0))from a_test 这个SQL现在就是得出的这个结果
SELECT* , SUM(num) as '总数'FROMtd_textWHERENAME IN ( SELECT NAME FROM td_text GROUP BY NAME HAVING count(NAME) > 1 )GROUP BY `name`td_text 表数据: 执行sql后
select distinct 品牌 from 表名 或者 select 品牌 from 表名 group by 品牌
不知道你的a,b两表有没有关联,假定没有关联 select count(1)from (select idfrom a where id>5union allselect id from b where id>5)
这个恐怕要用存贮过程或编程实现, 提个思路: 1) 创建一个同字段结构的新表table2 2) 按Col1排序 3) 循环每条记录, 记录每个字段值到临时变量中, 名为vCol1, vCol2... if (Col1 == 前一条记录vCol1) 累加vCol2, vCol3...(如果是字符串则相连) els...