Forum Discussion

pxg638's avatar
pxg638
Frequent Visitor
9 years ago
Solved

merging tables on two columns

Hi there, 

 

First post, so apologies if this is super dumb - I was either searching for the wrong thing or being exceedingly dense in understanding what others had written! I have a large (1m row) data table and a small (few hundred row) configuration table and I am trying to merge them together, thus:

 

Table.Data

Date Monthly Production Unit

31/1/20171000CNC1
31/1/20172000CNC2
31/1/20173000CNC3
28/2/20171000CNC1
28/2/20172000CNC2
28/2/20173000CNC3

 

etc

 

Table.Configuration

 

 

Date Unit Type1Jobs Type2Jobs

1/1/2017CNC10.50.5
1/2/2017CNC10.60.4
1/1/2017CNC20.50.5
1/1/2017CNC30.50.5
1/2/2017CNC301

 

In other words, for the month of Jan, CNC1 did 50% of Type1 jobs and 50% of type 2 jobs, and then in Feb was re-configured to do 60% type 1 jobs and 40% type 2 jobs.

 

The outcome I want is effectively:

 

 

Date Monthly Production Unit Type1Work Type2Work

31/1/20171000CNC1500500
31/1/20172000CNC210001000
31/1/20173000CNC315001500
28/2/20171000CNC1600400
28/2/20172000CNC210001000
28/2/20173000CNC303000

 

So the monthly production is shared out based on the fraction of the type of work, per machine. The end result I want to see is type of work over time per machine, as those get grouped by site.

 

Now, I can do a simple left outer join to achieve a baseline configuration, but I cannot do a join on two columns without getting into between/range type thinking and that is beyond my brain at this time, and therefore any configuration change of the machine is lost.

 

I see answers sort of suggesting a 2nd date table somehow, but I am struggling to see the solution. I am sure this is super simple, what am I missing?

 

 

  • Anonymous's avatar
    Anonymous
    9 years ago

    pxg638

     

    did you guys solve it with SQL after all?

     

    If so, could I ask you to accept a solution for this post, so others can benefit from it anyway?

16 Replies

  • vanessafvg's avatar
    vanessafvg
    Icon for Community Champion rankCommunity Champion

    pxg638 why dont you create a new column, ie a key based on the combination of  both the columns?

    • pxg638's avatar
      pxg638
      Frequent Visitor

      So I can create [Unit]&[Date] in both tables, that is simple enough, how would I then utilise that to create the change in allocation between jobtypes? Wouldn't a join on the new column simply leave lots of gaps where it didn't key up?

      • vanessafvg's avatar
        vanessafvg
        Icon for Community Champion rankCommunity Champion

        pxg638 ah ok, tell me a bit more about the change in allocation, its not clear to me from your post (i might be a bit slow this morning)