protected void Page_Load(object sender, EventArgs e)
{
// do connection Here.
string strShowing = "Select m.MovieName, m.Restriction, m.Language,s.StartTime from Movie m Inner Join Schedule s ON m.MovieID=s.MovieID";
conLoginDetails.Close();
如何将时间分组到相同的电影中。
答案 0 :(得分:0)
对于字符串连接,AFAIK,没有内置函数这样做。但您可以使用FOR XML
来执行此操作。像这样:
WITH CTE
AS
(
Select m.MovieName, m.Restriction, m.Language, s.StartTime
from Movie m
Inner Join Schedule s ON m.MovieID=s.MovieID
Where Status='Release'
)
SELECT
t1.MovieName,
t1.Restriction,
t1.Language,
STUFF((
SELECT ', ' + t2.StartTime
FROM CTE t2
WHERE t2.MovieName = t1.MovieName
FOR XML PATH (''))
,1,2,'') AS StartTime
FROM CTE t1
GROUP BY t1.MovieName,
t1.Restriction,
t1.Language;
使用此查询代替您已使用的查询:
string strShowing = "--put the query here--";
请注意:我使用CTE而不是在相关子查询中再次编写原始查询。