永发信息网

关于SQL Sever 2000中的多重条件查询

答案:4  悬赏:60  手机版
解决时间 2021-03-07 03:48
  • 提问者网友:暗中人
  • 2021-03-06 22:43
实例为:需要查询50001表中三个列(year,word,number)全部重复的条目
我编写的语句为
select * from tab50001 a where (a.year,a.word,a.number) in (select year,word,number from vitae group by year,word,number having count(*)>1)
而执行时,说我的‘,’附近出现了错误,经过分行查找,发现是
where (a.year,a.word,a.number)
此行出现的该错误,请问该语句有何问题?为何不能成功执行?

问题中的语句我复制错了,正确的应该为
select * from tab50001 a where (a.year,a.word,a.number) in (select year,word,number from tab50001 group by year,word,number having count(*)>1)
问题还是一样的
最佳答案
  • 五星知识达人网友:佘樂
  • 2021-03-06 23:49
sql不能这么写吧:(year,word,number)in

select a.* from tab50001 a ,(select year,word,number from tab50001 group by year,word,number having count(*)>1) b
where a.year = b.year and a.word = b.word and a.number = b.number
全部回答
  • 1楼网友:忘川信使
  • 2021-03-07 01:32
建议你先去补补SQL 的基础课。where 后面跟三个字段肯定是不符合语法规定的。另外,你在没有使用聚集操作的情况下使用group by 也是不对的。对于这个问题你不妨试试这个思路: 1.先用distinct 唯一选出原表中的所有记录,记为临时表 T 2.使用Except筛选原表与T表的差集 3.再用distinct 选出差集中的记录 所得结果就是原表中重复的记录了。SQL语句你自己试试,很容易。
  • 2楼网友:持酒劝斜阳
  • 2021-03-07 01:18
select a.* from tab50001 a ,(select year,word,number from tab50001 group by year,word,number having count(*)>1) b where a.year = b.year and a.word = b.word and a.number = b.number 一楼都写出来了》。。。
  • 3楼网友:十鸦
  • 2021-03-07 00:42
不知道你模糊查询什么?时间还用模糊,你是想查一个月,或者一年吗? where datediff(month,数据库里的字段名,输入的时间)=0 是筛选和输入的时间是一个月的数据都可以出来 是这个吗?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯