我想從數據庫中獲取的數據顯示,因爲這如何在範圍內顯示數據?
Total_marks | No of Students
10-20 | 2
20-30 | 1
30-40 | 3
so on
的樣本數據:
barcode(student id) | Total_marks
200056 | 70
200071 | 51
200086 | 40
200301 | 56
200317 | 73
200316 | 35
200217 | 42
200104 | 80
200015 | 63
我想:
SELECT
count(*) as no_of_students,
CASE
WHEN Total_marks BETWEEN 10 and 20 THEN '1'
WHEN Total_marks BETWEEN 20 and 30 THEN '2'
WHEN Total_marks BETWEEN 30 and 40 THEN '3'
WHEN Total_marks BETWEEN 40 and 50 THEN '4'
WHEN Total_marks BETWEEN 50 and 60 THEN '5'
WHEN Total_marks BETWEEN 60 and 70 THEN '6'
WHEN Total_marks BETWEEN 70 and 80 THEN '7'
WHEN Total_marks BETWEEN 80 and 90 THEN '8'
WHEN Total_marks BETWEEN 90 and 100 THEN '9'
END AS intervals
FROM
[database]
WHERE
0 - 10 = '0' and 10 - 20 = '1' and 20 - 30 = '2' and 30 - 40 = '3' and 40 - 50 = '4' and 50 - 60 = '5' and 60 - 70 = '6' and 70 -80 = '7' and 80 - 90 = '8' and 90 - 100 = '9' GROUP BY Total_marks
但我剛剛得到的列標題,並沒有數據。如何正確制定查詢。此外,我希望這將顯示爲在ASP.NET中的圖表。其中,代碼如下:
{
connection.Open();
SqlCommand cmd = new SqlCommand("Query", connection);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable ChartData = ds.Tables[0];
//storing total rows count to loop on each Record
string[] XPointMember = new string[ChartData.Rows.Count];
Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
decimal[] YPointMember = new decimal[ChartData.Rows.Count];
int totalrows = ChartData.Rows.Count;
if (totalrows > 0)
{
for (int count = 0; count < ChartData.Rows.Count; count++)
{
//storing Values for X axis
XPointMember[count] = ChartData.Rows[count]["Number_of_students"].ToString();
//storing values for Y Axis
YPointMember[count] = Convert.ToDecimal(ChartData.Rows[count]["Total_accumulated_score_achieved" + "%"]);
connection.Close();
}
你能提供樣品的數據嗎? – RoundFour