`

用sql语句查询某表中拥有多个相同字段中的一个值

 
阅读更多
1、对自己的表操作
select  a.* from hdzx_question a  where a.c_id=(select top 1 c_id from hdzx_question  where c_title
=a.c_title and substring(c_content,0,7000)=substring(a.c_content,0,7000))  (注:c_content是text类型)


2、如:有表:t1
name  number  money  month
...........................
a1    123       10     3
a1    123       5      3
a1    123       7      3
a2    258       4      4
a2    258       2      4
a3    147       1      1
a4    256       7      1
如何用sql语句查出符合如下条件的结果:
name和number相同的只取一条记录(随便一条),显示这条所有字段
如最后结果应为:
name  number  money  month
...........................
a1    123       10     3
a2    258       4      4
a3    147       1      1
a4    256       7      1

解决方法:
select * from t1 as t where id = (select top 1 id from t1 where name=t.name and number=t.number)


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics