0

我需要生成虚拟表并用日期值范围填充它。

以下查询通常在 MySql 中执行:

SELECT DATEID, STR_TO_DATE(DateValue, '%Y-%m-%d %H:%i:%s') AS DateValue FROM(
 SELECT CONVERT(DATE_FORMAT(ADDDATE(@day, INTERVAL @row1+1 DAY),'%Y%m%d'), UNSIGNED) AS DATEID, 
                                    @day := ADDDATE(@day, INTERVAL @row1+1 DAY) AS DateValue, 
                                    @row2 := @row2 + 1 AS row2
                                    FROM `INFORMATION_SCHEMA`.COLUMNS a, 
                                        (SELECT @row1 := 0) r, 
                                        (SELECT @row2 := 0) r2, 
                                        (SELECT @day := DATE_SUB('2000-01-01', INTERVAL 1 DAY)) d 
                                WHERE @row2 <= DATEDIFF('2020-01-01', '2000-01-01') ) as Result

结果: 在此处输入图像描述

如何使用 MongoDB BI 连接器获得准确的结果?

问题是 ':=' 赋值语法不起作用。

mongosqld 开始于 localhost:3307

 public IDataReader ExecuteReader()
    {
        try
        {
            var connection = new MySqlConnection("Server=localhost;Port=3307;Database=masterDb;");

            var sqlQuery = @"SELECT DATEID, STR_TO_DATE(DateValue, '%Y-%m-%d %H:%i:%s') AS DateValue FROM(
                                SELECT CONVERT(DATE_FORMAT(ADDDATE(@day, INTERVAL @row1+1 DAY),'%Y%m%d'), UNSIGNED) AS DATEID, 
                                    @day := ADDDATE(@day, INTERVAL @row1+1 DAY) AS DateValue, 
                                    @row2 := @row2 + 1 AS row2
                                    FROM `INFORMATION_SCHEMA`.COLUMNS a, 
                                        (SELECT @row1 := 0) r, 
                                        (SELECT @row2 := 0) r2, 
                                        (SELECT @day := DATE_SUB('2000-01-01', INTERVAL 1 DAY)) d 
                                WHERE @row2 <= DATEDIFF('2020-01-01', '2000-01-01') ) as Result";

            if (connection.State != ConnectionState.Open)
                connection.Open();

            var command = connection.CreateCommand();

            command.CommandText = sqlQuery;
            command.CommandType = CommandType.Text;
            command.CommandTimeout = ConnectionConstants.DefaultCommandTimeout;

            return command.ExecuteReader();

        }
        catch (Exception ex)
        {
            throw new ConnectorException(Sections.QueryExecution, ex.Message);
        }
    }

如果输入值为 startDate = "2000-01-01" endDate = "2000-01-05"

输出表应为: 在此处输入图像描述

4

0 回答 0