我想要找到记录的总数

时间:2015-01-08 05:56:26

标签: sql subquery

    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

我想要查看这些找到的记录,我可以在此查询中获得最大行号吗?

2 个答案:

答案 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;