我想在asp.net中生成一個sql server數據庫的報告,我得到一些列作爲兩列產品的結果。下面是代碼Sql加入多列表返回兩列的產品
comm.CommandText = "SELECT Count(Courses.CourseID) AS CourseCount, Count(Students.StudentID) AS StudentCount, Schools.Name, Schools.StartDate, Schools.SchoolFees " +
"FROM Schools" +
"LEFT JOIN Courses ON (Schools.SchoolID = Courses.SchoolID)" +
"LEFT JOIN Students ON (Schools.SchoolID = Students.SchoolID) " +
"WHERE Schools.Active = 1 " +
"GROUP BY Schools.Name, Schools.StartDate, Schools.SchoolFees";
當運行的代碼,其結果顯示,但對於「CourseCount」和「StudentCount」的列顯示一個值,該值是每個單獨的柱的產物。 「CourseCount」通常是288,「StudentCount」是38,但是當我運行代碼時,「CourseCount」和「StudentCount」顯示10944爲38 x 288.
無論如何,我可以讓他們顯示正確的值?
效果很好!非常感謝@rossquan。 – elfico