简体   繁体   English

如何以Crystal提取数据的方式从表中提取所需数据?

[英]How to pull required data from table the way Crystal is pulling it?

I have a view set up like the below table, which is pulling data from multiple other tables using JOINS. 我有一个类似下表的视图,该视图使用JOINS从多个其他表中提取数据。 Basically I'm trying to replicate a Crystal Report that breaks up the data below into Job # - Weekly (hrs) - TotalToDate(hrs) - Budget(hrs) 基本上,我正在尝试复制一个Crystal Report,将下面的数据分解为Job#-每周(小时)-TotalToDate(小时)-预算(小时)

And this is broken up per department. 这是每个部门分解的。 The way the report does it is it'll display the hours for the last week, then the total hours to date then the budgeted hours set for that department. 报告的方式是显示上周的小时数,然后显示迄今为止的总时数,然后显示该部门设置的预算时数。 图片供参考

Table doesn't reflect above - just an example of what DB table looks like. 表在上面没有反映-只是数据库表看起来的一个示例。

    +-----------+------------+---------------+--------+---------------------+
    | Job       |  Work_Date | Work_Center   | Est_Total_Hrs | Act_Run_Hrs  |
    +-----------+------------+---------------+--------+------+--------------+
    |      5666 | 2014-02-23 | SURFACE       |     155       |      5       | 
    |      5666 | 2014-02-16 | SURFACE       |     155       |      3       |      
    |      5666 | 2014-02-23 | DESIGN        |     200       |      6       |      
    |      5666 | 2014-02-16 | DESIGN        |     200       |      4       |       
    |      5666 | 2014-02-23 | SURFACE       |     150       |      2       |      
    |      5666 | 2014-02-16 | SURFACE       |     150       |      2       |       
    |      5666 | 2014-02-23 | DESIGN        |     300       |      8       |       
    +-----------+------------+---------------+---------------+--------------+

Also, theres a lot of different job numbers, and when I pull up more than 1 job in Crystal it'll show the report like the picture above but with all jobs I want to retrieve. 此外,还有很多不同的工作编号,当我在Crystal中拉出1个以上的工作时,它将显示如上图所示的报告,但包含要检索的所有工作。

How would I go about pulling this data so it shows up the same way in the Crystal Report? 我将如何提取这些数据,以使其在Crystal Report中以相同的方式显示? I want to create a view that looks the same. 我想创建一个看起来一样的视图。 Is there a way to see how Crystal does it? 有没有办法看水晶的效果? When I click "Show Query" it shows me the below query which I had to re-write a little bit for it to work in SQL Server and in Adminer. 当我单击“显示查询”时,它向我显示以下查询,我必须重新编写一下才能在SQL Server和Adminer中工作。

Query I'm using to pull ALL data for all Jobs within an updated Work_Date in the last 90 days. 我正在使用查询来查询过去90天内更新的Work_Date中所有作业的所有数据。

SELECT Job_Operation.Work_Center
    ,Job_Operation.Job_Operation
    ,Job_Operation_Time.Work_Date
    ,Job_Operation.Est_Total_Hrs
    ,Job_Operation_Time.Act_Run_Hrs
    ,Job_Operation_Time.Act_Setup_Hrs
    ,Job.Description
    ,Job_Operation_Time.Overtime_Hrs
    ,Job_Operation_Time.Act_Setup_Hrs
    ,Job.Job
    ,Job.Description
    ,Job_Operation_Time.Labor_Burden
    ,Job_Operation.Est_Setup_Labor
    ,Job_Operation.Est_Run_Labor
    ,Job_Operation.Est_Labor_Burden
    ,Job_Operation.Operation_Service
FROM Job AS Job 
LEFT OUTER JOIN Job_Operation AS Job_Operation ON Job.Job = Job_Operation.Job
LEFT OUTER JOIN Job_Operation_Time AS Job_Operation_Time ON Job_Operation.Job_Operation = Job_Operation_Time.Job_Operation
WHERE DATEDIFF(day, Work_Date, GETDATE()) < 90 ORDER BY Work_Date Desc

Crystal will take the data from a query and does its internal manipulation as per the design of the report, So if you need the table exactly as you view the report then along with the query in crystal report you need to make some changes. Crystal将从查询中获取数据,并根据报表的设计对其内部进行操作,因此,如果您在查看报表时完全需要表,则需要与Crystal报表中的查询一起进行一些更改。

Suggestions: 建议:

  1. Your report has only 6 columns but you query has more than 10 columns so you need to change the query so that it has only 6 columns. 您的报告只有6列,但查询有10列以上,因此您需要更改查询以使其只有6列。

  2. Report has data according to the week but query has hourly data so you need to write some functions in query so that you manage to get weekly data from hour data 报表具有根据星期的数据,但是查询具有每小时的数据,因此您需要在查询中编写一些函数,以便设法从每小时的数据中获取每周数据

  3. You said when you take more than 1 ID you get in the given format then in that case add some group by conditions to the resultant query so that all data is grouped. 当你超过你说1号,你在给定的格式得到那么在这种情况下,增加一些group by条件,得到的查询,以便所有数据分组。 for eg if you need only one ID then group by ID so that there is only one record for a ID. 例如,如果您仅需要一个ID,则按ID进行分组,以便ID仅有一条记录。

  4. Try adding some group by conditions some date formulas to get exact output 尝试group by条件添加一些group by一些日期公式以获得准确的输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM