Select (RowNo),
*,
(Select TOP 1 Name From TourImages Where TourImages.TourID = T.ID Order By T.ID Desc)
as TourImageName
FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY Tours.MinPrice Asc) s RowNo
From Tours Where (AgentID = 10) AND (MinPrice > 1) AND (MinPrice < 99999)
AND (IsActive =1) AND (IsDeleted=0) AND (IsSync=1)) as T Where T.RowNo > 0
我想要查看这些找到的记录,我可以在此查询中获得最大行号吗?
答案 0 :(得分:0)
with cte as (Select (RowNo)RowNo,
*,
(Select TOP 1 Name From TourImages Where TourImages.TourID = T.ID Order By T.ID Desc)
as TourImageName
FROM (SELECT *,ROW_NUMBER() OVER(ORDER BY Tours.MinPrice Asc) s RowNo
From Tours Where (AgentID = 10) AND (MinPrice > 1) AND (MinPrice < 99999)
AND (IsActive =1) AND (IsDeleted=0) AND (IsSync=1)) as T Where T.RowNo > 0)
select max(RowNo),count(*) from cte
答案 1 :(得分:-1)
COUNT(*)函数返回表中的记录数:
SELECT COUNT(*)FROM table_name;