SQL Query查找列中元素的频率

时间:2016-03-29 10:47:51

标签: sql asp.net

在HelpDesk系统中,我有一个表(请求),其中包含一个colume(状态:打开,正在进行,已关闭)

我想要一个Query来比较打开请求和已关闭请求的数量,使用VisualStudio图表

我尝试使用此SQL查询来计算打开和关闭请求的频率, 但是语法错误

SELECT [Status] COUNT[Status] AS Frequency
FROM [RequestF] GROUP BY [Status]

 asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1">
                           <Series>
    <asp:Series Name="Series1" XValueMember="Status"  ChartType="Pie"></asp:Series>
</Series>
<ChartAreas>
    <asp:ChartArea Name="ChartArea1">
        <AxisY>
            <LabelStyle Format="P0" />
        </AxisY>
    </asp:ChartArea>
</ChartAreas>

                       </asp:Chart>
                       <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BiomedicalSampleConnectionString %>" SelectCommand="SELECT [Status] COUNT[Status] AS Frequency FROM [RequestF] GROUP BY [Status] "></asp:SqlDataSource>

1 个答案:

答案 0 :(得分:0)

试试这个:

SelectCommand="SELECT Status,COUNT(Status) AS Frequency FROM RequestF GROUP BY Status"