是这样的:Prudocts表是ProductId,ProductName,CategoryId字段,Category表,字段有CategoryId,Depth字段
我现在要取出Product表中的ProductId,ProductName,CategoryId前4项数据,要求是Product表中的CategoryId属于Category表,且Depth=1,我自己写的SQL语句如下:
select a.ProductId,a.CategoryId,a.ProductName from Products a
where (select count(*) from Products a where CategoryId in
(select b.CategoryId from Category b where b.Depth=1) and ProductId<a.ProductId)<4
order by CategoryId
查询结果永远不对。。。。我搞了好久的,请各方朋友出手帮一下,在线等。。。
------解决方案--------------------