在开发考试系统中,题库的题有一些是重复的,题目内容完全一样,需要对text类型的字段值进行重复检查,实现思路如下:
1、把qcontent的text字段转成varchar
用cast方法:
cast(qcontent as varchar(4000)) as qcontent
2、查询内容大于1的sql语句:
select cast(qcontent as varchar(4000)) as qcontent from ExamWeb_QuestionBank group by cast(qcontent as varchar(4000)) having count (cast(qcontent as varchar)) > 1
![0b816bf0b8bfd03cc9e2a06eb72733c5.png](https://i-blog.csdnimg.cn/blog_migrate/427a53ed232d6a39725658b792c75a81.png)
这些试题内容是重的
3、如果要把重复数据一一输出的SQL语句:
select * from ExamWeb_QuestionBank where (cast(qcontent as varchar(4000))) in (select cast(qcontent as varchar(4000)) as qcontent from ExamWeb_QuestionBank group by cast(qcontent as varchar(4000)) having count (cast(qcontent as varchar)) > 1)