从查询中获取计数
get the count from query
Select Count(*),
(select Name from Tours Where Tours.ID = TourBooking.TourID) as Name,
(select Url from Tours Where Tours.ID = TourBooking.TourID) as Url,
(select Top 1 Name from TourImages Where TourImages.TourID = TourBooking.TourID Order By ID Asc) as ImageName,
(Select Duration +' '+ CASE WHEN DurationType = 'd' THEN 'Day(s)' WHEN DurationType = 'h' THEN 'Hour(s)' END from Tours Where Tours.ID = TourBooking.TourID)as Duration,
(select replace(replace('<a> Adult(s) - <c> Children','<a>', sum(case when [Type] = 1 then 1 else 0 end) ),
'<c>', sum(case when [Type] = 2 then 1 else 0 end)) from TourPerson Where TourPerson.BookingId = TourBooking.ID) as TotalPassengers,
StartDate,CreatedDate as BookingDate,ID as BookingID,[Status],ServicePrice
from TourBooking
如何从此查询中获取计数
How to get the count from this query
我认为您试图在您的第一个COUNT(*)
声明中做到这一点。相反,您可以尝试嵌套整个查询并以这种方式获取计数。
SELECT COUNT(innerTable.*), innerTable.* FROM (
SELECT
(select Name from Tours Where Tours.ID = TourBooking.TourID) as Name,
(select Url from Tours Where Tours.ID = TourBooking.TourID) as Url,
(select Top 1 Name from TourImages Where TourImages.TourID = TourBooking.TourID Order By ID Asc) as ImageName,
(Select Duration +' '+ CASE WHEN DurationType = 'd' THEN 'Day(s)' WHEN DurationType = 'h' THEN 'Hour(s)' END from Tours Where Tours.ID = TourBooking.TourID)as Duration,
(select replace(replace('<a> Adult(s) - <c> Children','<a>', sum(case when [Type] = 1 then 1 else 0 end) ),
'<c>', sum(case when [Type] = 2 then 1 else 0 end)) from TourPerson Where TourPerson.BookingId = TourBooking.ID) as TotalPassengers,
StartDate,CreatedDate as BookingDate,ID as BookingID,[Status],ServicePrice
from TourBooking ) as innerTable
Select Count(*),
(select Name from Tours Where Tours.ID = TourBooking.TourID) as Name,
(select Url from Tours Where Tours.ID = TourBooking.TourID) as Url,
(select Top 1 Name from TourImages Where TourImages.TourID = TourBooking.TourID Order By ID Asc) as ImageName,
(Select Duration +' '+ CASE WHEN DurationType = 'd' THEN 'Day(s)' WHEN DurationType = 'h' THEN 'Hour(s)' END from Tours Where Tours.ID = TourBooking.TourID)as Duration,
(select replace(replace('<a> Adult(s) - <c> Children','<a>', sum(case when [Type] = 1 then 1 else 0 end) ),
'<c>', sum(case when [Type] = 2 then 1 else 0 end)) from TourPerson Where TourPerson.BookingId = TourBooking.ID) as TotalPassengers,
StartDate,CreatedDate as BookingDate,ID as BookingID,[Status],ServicePrice
from TourBooking
如何从此查询中获取计数
How to get the count from this query
我认为您试图在您的第一个COUNT(*)
声明中做到这一点。相反,您可以尝试嵌套整个查询并以这种方式获取计数。
SELECT COUNT(innerTable.*), innerTable.* FROM (
SELECT
(select Name from Tours Where Tours.ID = TourBooking.TourID) as Name,
(select Url from Tours Where Tours.ID = TourBooking.TourID) as Url,
(select Top 1 Name from TourImages Where TourImages.TourID = TourBooking.TourID Order By ID Asc) as ImageName,
(Select Duration +' '+ CASE WHEN DurationType = 'd' THEN 'Day(s)' WHEN DurationType = 'h' THEN 'Hour(s)' END from Tours Where Tours.ID = TourBooking.TourID)as Duration,
(select replace(replace('<a> Adult(s) - <c> Children','<a>', sum(case when [Type] = 1 then 1 else 0 end) ),
'<c>', sum(case when [Type] = 2 then 1 else 0 end)) from TourPerson Where TourPerson.BookingId = TourBooking.ID) as TotalPassengers,
StartDate,CreatedDate as BookingDate,ID as BookingID,[Status],ServicePrice
from TourBooking ) as innerTable