本文介绍了SQL Server:In with和condition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有简单的查询,我使用IN关键字我想只显示包含所有项目的行。 示例:我有两个表1)视频2)类别 选择Video.videoid,title,categoryid来自Video.portalid上的视频连接类别= Category.portalid其中Category.CategoryId in(1,2,3) ) 此查询返回所有类别为1或2或3等的记录,但我只想显示具有所有这三个categoryId值的行。 br /> 我也在使用group by但我觉得我错过了什么.. select Video.videoid ,标题,类别来自视频连接类别视频.portalid = Category.portalid其中Category.CategoryId in(1,2,3) group by Video.VideoId,title,categoryid 有计数(不同的categoryid)= 3 我尝试了其他方式,但我还没有成功。解决方案 I have simple query, i am using IN keyword I want to show only rows that have all the item.Example : i have two table 1)Video 2) Categoryselect Video.videoid, title, categoryid from Video join Category on Video.portalid=Category.portalid where Category.CategoryId in (1,2,3)This query return all the record that have category id 1 or 2 or 3 etc. but I want to show only rows that have all those three categoryId values.I am also using group by but i think i am missing something..select Video.videoid, title, categoryid from Video join Category on Video.portalid=Category.portalid where Category.CategoryId in (1,2,3)group by Video.VideoId,title,categoryidhaving count(distinct categoryid ) = 3I tried some other way but I did not succeed yet. 解决方案 这篇关于SQL Server:In with和condition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 03:19