0

我正在从 Mysql 数据库中检索数据,查询是这样的:

SELECT
DATE(cap_newspaper_page.insertDate) AS _Date,
count(*) AS Image_Captured
FROM
cap_newspaper_page
WHERE 
cap_newspaper_page.insertDate BETWEEN '2012-11-01' AND '2012-11-13'
GROUP BY
DATE(cap_newspaper_page.insertDate)
ORDER BY
DATE(cap_newspaper_page.insertDate)

数据显示为 在此处输入图像描述

但我也想显示未插入数据库的 Null 值。像 2012-11-03、2012-11-04、2012-11-09、2012-11-11 没有插入数据库中,但我想将它们显示为 Null 或 0。喜欢

  1. 2012-11-01 581
  2. 2012-11-02 587
  3. 2012-11-03 0/无
  4. 2012-11-04 0/无
  5. 2012-11-05 752
  6. 2012-11-06 690
  7. 2012-11-07 495
  8. 2012-11-08 623
  9. 2012-11-09 0/无
  10. 2012-11-10 921
  11. 2012-11-11 0/无
  12. 2012-11-12 755

有任何想法吗??

4

1 回答 1

0

我假设您的日期在从数据库中读取后处于某种数据结构中。让我们假设它可以是一个数组,你可以使用这样的东西(只是一个例子):

DateTime[] dts = new DateTime[4];
dts[0] = DateTime.Now.AddDays(-15);
dts[1] = DateTime.Now.AddDays(-4);
dts[2] = DateTime.Now.AddDays(1);
dts[3] = DateTime.Now.AddDays(4);

DateTime dtMax = dts.Max();
DateTime dtMin = dts.Min();
string str = string.Empty;
for (DateTime i = dtMin; i <= dtMax; i = i.AddDays(1))
{
     str += i.ToString("MM.dd.yyyy");
     str += Environment.NewLine;
}
于 2012-11-13T10:12:49.510 回答