34,593
社区成员
发帖
与我相关
我的任务
分享
select * from product where id in
(select top 50 productId from comment t where not exists(select 1 from comment where productId=t.productId
and id>t.id))
SELECT * FROM TABLE A
CROSS APPLY
(
SELECT TOP(50) * FROM TABLE B WHERE A.ID=B.ID
) B
select * from (SELECT *,ROW_NUMBER() OVER(ORDER BY 时间 desc ,id desc) as num FROM PRODUCT JOIN comment on product.id = comment.productId) a where a.num>=50
select top 50 * from product inner join comment on product.id = comment.productId 再加上评价的时间 desc
--如果有评论时间则,按照评论时间排序
select top 50 P.*,C.* from product P join comment C on C.productId =P.id order by '评论时间'
--如果有自增ID ,则按照ID排序
select top 50 P.*,C.* from product P join comment C on C.productId =P.id order by 自增ID
--楼主不妨给点数据,别让大家猜
select top 50 P.*,C.* from product P join comment C on C.productId =P.id order by '评论时间'
[Quote=引用楼主 transposon 的帖子:]
如题,一个product表,一个comment表,关联是 product.id = comment.productId
要求查出 最新评论的50个产品
貌似是个比较简单的sql,不知咋回事就是写不出来了
[/Quote]
select P.*,C.* from product P join comment C on C.productId =P.id order by '评论时间'