关于如何处理返回不同行的数据集的逻辑计算每个分组 [英] Logic on how to process dataset that returns different rows counts for each grouping

查看:48
本文介绍了关于如何处理返回不同行的数据集的逻辑计算每个分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,对我来说这是一个奇怪的事情,我在处理数据集的过程中遇到困难。一点背景 - 我正在从提交带有一些问题的表单的个人的DNN数据库中检索数据。根据他们如何回答一些问题,可能需要额外的字段来处理。然后我将这些数据推送到遗留数据库中,因此我必须处理答案,然后将它们连接起来以适应遗留数据库。



可能返回字段的示例(这些是以行而不是列的形式返回):



名称

电子邮件

手机

事件类型(取决于是否返回下一个字段的答案)

指定其他字段(可能包含也可能不包含在数据集中)

day
>
时间

预算

您是如何得知我们的(取决于答案可能多达四个字段)

(可以返回以下0 - 4)

指定网络搜索

指定员工

指定推荐

指定其他



对于事件类型,只有一种类型的答案会导致指定其他答案,因此我可以在其上执行if语句。如果是真的那么我在行数中添加一个,所以我不会丢失我正在处理的字段,但是对于最后一个我感到难过,因为我不想输入很多if语句而且我可以不要做一个案例陈述,因为有太多的组合来回答哪些字段。我没有创建此数据来自的表单,因此我无法控制更改它。



如果有人知道处理这样的事情的例子我会很感激〜否则给我一些关于如何处理指定答案的指针就没问题。



谢谢,

Carolyn

解决方案

我能够解决这个问题通过使用if语句的组合并循环遍历主行处理后剩下的任何行。



因为rowValue上面的额外输入字段只是如果字段存在则将所有内容递增1的方法,如果不存在,则使用正常的行号。



 < span class =code-keyword>如果 ds.Tables( 0 )。Rows.Count()> ( 11  + rowValue)然后 
For i =( 11 + rowValue) ds.Tables( 0 )。Rows.Count()
如果 ds.Tables( 0 ).Rows(i).Item( DynamicQuestionID)= GUID 然后
指定其他+ = 名称: &安培; ds.Tables( 0 )。行(i).Item( response
ElseIf ds.Tables( 0 )。行(i).Item( DynamicQuestionID)= GUID 然后
指定其他+ = 搜索:& ds.Tables( 0 )。行(i).Item( response
ElseIf ds.Tables( 0 )。行(i).Item( DynamicQuestionID)= GUID 然后
specifiedOther = 推荐人:& ds.Tables( 0 )。行(i).Item( response
ElseIf ds.Tables( 0 )。行(i).Item( DynamicQuestionID)= GUID 然后
指定其他= 其他:& ds.Tables( 0 )。行(i).Item( 响应
否则
specifiedOther = 指定:& ds.Tables( 0 )。行(i).Item( 响应
结束 如果

i + = 1
下一步
结束 如果


Okay this to me is a weird one and I'm having trouble wrapping my brain around the way I should process the dataset. A little background - I'm retrieving data from a DNN database that is individuals submitting a form with some questions. Based on how they answer some of the questions there maybe extra fields to process. I'm then shoving this data into a legacy database so I have to process the answers and then concatenate them to fit the legacy database.

Sample of possible returned fields (these are returned as rows not columns):

Name
email
phone
event type (depending on answer on whether the next field is returned or not)
specify other (may or may not be included in dataset)
day
time
budget
how did you hear about us(depending on answer could be up to four more fields)
(0 - 4 of the following may be returned)
specify web search
specify employee
specify referral
specify other

For the event type only one type of answer causes the specify other to be answered so I can do an if statement on it. And if true then I add one to the row count so I don't lose which field I'm processing, but for the last one I'm stumped because I don't want to put in a lot of if statements and I can't do a case statement because there are too many combinations of which fields have been answered. I didn't create the form this data is coming from so I have no control over changing it.

If someone knows of an example handling something like this I would appreciate it ~ otherwise giving me some pointers on how to process the set of specify answers would be okay.

Thanks,
Carolyn

解决方案

I was able to solve this by using a combination of an if statement and looping through any rows that were left after the main rows had been processed.

Because of the extra input field above rowValue is just a way to increment everything by one if the field exist and if it doesn't then it uses the normal row number.

If ds.Tables(0).Rows.Count() > (11 + rowValue) Then
        For i = (11 + rowValue) To ds.Tables(0).Rows.Count()
            If ds.Tables(0).Rows(i).Item("DynamicQuestionID") = GUID Then
                specifyOther += " Name: " & ds.Tables(0).Rows(i).Item("response")
            ElseIf ds.Tables(0).Rows(i).Item("DynamicQuestionID") = GUID Then
                specifyOther += " Search: " & ds.Tables(0).Rows(i).Item("response")
            ElseIf ds.Tables(0).Rows(i).Item("DynamicQuestionID") = GUID Then
                specifyOther = "Referrer: " & ds.Tables(0).Rows(i).Item("response")
            ElseIf ds.Tables(0).Rows(i).Item("DynamicQuestionID") = GUID Then
                specifyOther = " Other: " & ds.Tables(0).Rows(i).Item("response")
            Else
                specifyOther = " Specify: " & ds.Tables(0).Rows(i).Item("response")
            End If
           
            i+=1
        Next
    End If


这篇关于关于如何处理返回不同行的数据集的逻辑计算每个分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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