在mysql视图中使用row_count作为ID列的问题

时间:2017-08-11 18:44:42

标签: mysql sql view

我正在使用此查询创建视图:

create view daily_report as 

SELECT 
      row_count()
    , c.extension as Extension
    , RESPONSIBLEUSEREXTENSIONID as ExtID
    , count(DISTINCT b.NOTABLECALLID) as Total_Calls
    FROM cdrdb.session a
    LEFT JOIN cdrdb.callsummary b
            ON a.NOTABLECALLID = b.NOTABLECALLID
    LEFT JOIN cdrdb.mxuser c
          ON a.RESPONSIBLEUSEREXTENSIONID = c.EXTENSIONID
    GROUP BY c.extension;

它取得了成功,但是当我从视图中选择记录时,它将-1作为所有6条记录的值。

我不确定我做错了什么。确切地说。

2 个答案:

答案 0 :(得分:1)

对于返回结果集的语句(例如SELECT,SHOW,DESC或HELP),返回-1,即使结果集为空。对于管理语句也是如此,例如OPTIMIZE。

答案 1 :(得分:1)

https://dev.mysql.com/doc/refman/5.7/en/information-functions.html

  

SELECT:如果语句返回结果集,则为-1,
  或者“受影响”的行数,如果没有。

例如,

private void chart_MouseWheel(object sender, MouseEventArgs e)
{
    try
    {
        if (e.Delta < 0)
        {
            chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
            chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
        }

        if (e.Delta > 0)
        {
            double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
            double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
            double yMin = chart1.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
            double yMax = chart1.ChartAreas[0].AxisY.ScaleView.ViewMaximum;

            double posXStart = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMin)/2;
            double posXFinish = (chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + xMax)/2;
            double posYStart = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMin)/2;
            double posYFinish = (chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + yMax)/2;

            chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
            chart1.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish);
        }
    }
    catch { }
}