用关键字 stinct,select stinct 字段,是不重复的意思。代码的实例如下:
查询order_id和loan_lind两个字段相同的记录:
select distinct a.order_preview_id, a.order_id, a.loan_kind
from ddk_order_preview_info a
join ddk_order_preview_info b
on a.order_preview_id != b.order_preview_id
where a.order_id = b.order_id and a.loan_kind = b.loan_kind
扩展资料
SQL数据库查询出一张表中重复的数据,按某个字段来查找的实例:
例如表名为Course:
需要查询出name的重复,解答如下:
补充:
如:查询每个姓名出现大于2次,SQL如下
SELECT COUNT(NAME) as '出现次数', NAME FROM 表名
GROUP BY NAME HAVING count(NAME) >2 ORDER BY 出现次数 DESC
参考资料来源:MySql官方网站-MySQL 8.0参考手册-13.2.10 SELECT语法
Select a.*From Table1 a,Table1 b
Where a.cid<>b.cid
And a.type=b.type
And a.date1=b.date1
And a.type between 1 and 3
Group By a.type,a.data1,a.cid
假设表名为Table1。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)