-1

我有三张桌子

private static final String DTReasonTable = "create table tb_DTReasons(DTReasonId integer primary key autoincrement,DTReason text)";

private static final String ConfigurationTable = "create table tb_Config(ConfigId integer primary key autoincrement," +
        "RawMaterialName text,OutPut_pdt text,TotalWorkHrs real,Quantity real,ProcessStartTime real,OutputQuantity real,procesEndTime real)";

private static final String DownTimeTable = "create table tb_DownTimeTable(DT_Id integer primary key autoincrement,ConfigId integer," +
        "StartTime real,EndTime real,DTReasonId integer)";

我想创建一个如下所示的报告

在此处输入图像描述

谁能帮我写一个相应的报告生成程序?

  public Cursor getDtAnalysisReport()
{
    return this.data.rawQuery("select EndTime-StartTime as duration,tb_DTReasons.DTReason,count(tb_DownTimeTable.DTReasonId) from tb_DownTimeTable" +
            " inner join tb_DTReasons on tb_DownTimeTable.DTReasonId = tb_DTReasons.DTReasonId group by tb_DownTimeTable.DTReasonId ", null);

}

这是我尝试过的,但出现错误。请帮我找到解决方案。

4

1 回答 1

0
SELECT DTReason AS 'Down Time Reason',
       SUM(EndTime - StartTime) AS 'Duration',
       SUM(EndTime - StartTime) /
       (SELECT SUM(EndTime - StartTime)
        FROM tb_DownTimeTable
       ) * 100 AS '% Total Down Time',
       COUNT(*) AS 'No of Occurrences'
FROM tb_DTReasons
JOIN tb_DownTimeTable ON tb_DTReasons.DTReasonId = tb_DownTimeTable.DTReasonId
GROUP BY tb_DTReasons.DTReasonId
于 2013-05-20T12:21:58.290 回答