将来自两个数据源的数据合并到一个表中 [英] Combine data from two datasources into a single table

查看:257
本文介绍了将来自两个数据源的数据合并到一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据集:

  1. 数据集1 -记录一次商店访问的详细信息.商家名称,位置,日期和与SKU(数据集2)的关系
  2. 数据集2 -这是SKU数据,其中每个sku的库存水平作为新记录输入,每个记录都与数据集1的访问相关.
  1. Dataset 1 - Records the details of a store visit. Merchandiser name, location, date & a relation to SKU (Dataset 2)
  2. Dataset 2 - This is the SKU data, where the stock levels for each sku are input as a new record, each associated to a visit from Dataset 1.

我有两个问题:

  1. 我想将此数据合并到一个表中.我想显示每个SKU记录,以及用于访问信息(例如位置和日期)的其他列.我该怎么做.

  1. I want to combine this data into a single table. I want to show each SKU record, with additional columns for the visit information (such as the location & date). How do I do this.

如何合并这些数据以在其他地方使用,例如Google Data Studio.本质上,我希望能够查看SKU的库存水平的历史记录或上次更新的日期.

How do I combine this data for use elsewhere, such as google data studio. Essentially I want to be able to see an SKU's stock-level's history, or the date it was last updated.

推荐答案

您需要创建计算数据源.您可以参考示例.

You need to create Calculated Data Source. You can refer this sample.

高水平

  1. 在Appmaker中添加数据源.
  2. 选择计算所得",提供名称"并创建数据源.

一旦您的计算模型就位.根据需要添加字段.例如如果要存储两个字段的总和,请在计算模型"中创建一个整数"字段.这是您计算出的数据模型的样子.

Once your Calculated Model is in place. Add fields as per need basis. e.g. If you want to store Sum of two fields, create one Integer field in Calculated Model. Here's how your calculated data model will look like.

现在转到第二个选项卡,即数据源".单击那里的数据模型名称.您应该看到一个编写服务器端脚本的选项.

Now go to Second Tab which is "Datasources". Click on the Data Model name there. You should see an option to write server side script.

在这里,您应该编写用于组合数据源的逻辑.我可以为您提供一个示例来实现这一目标.

Here you should write your logic for combining your data sources. I can provide you one sample to achieve this.

//server script
var calculatedModelRecords = [];
var recordsByStatus = {};
var allRecord = app.models.Request.newQuery().run(); //your existing data source.


for (var i = 0; i < allRecord.length; i++) {
     var record = allRecord[i];
    var draftRecord = app.models.TAT.newRecord(); //new data source 
    draftRecord.CreatedOn = record.CreatedOn;
    draftRecord.DocumentName = record.DocumentName;
    draftRecord.DueDate = record.DueDate;
    draftRecord.DaysPerStage = record.DaysPerStage;  
    draftRecord.Status = record.Status;  
  calculatedModelRecords.push(draftRecord);    
}

return calculatedModelRecords;

这篇关于将来自两个数据源的数据合并到一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆