Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Unir dos tablas con muchos a muchos campos de relación

Estoy trabajando en el estudio de datos de Google e intento obtener los datos de un sistema de terceros. En ese caso, hay un problema en el sistema de terceros, porque no permite la combinación de SQL. Por lo tanto, obtuve los datos usando 2 URL por separado y uní las dos tablas (tabla de pedido_cliente y tabla Demanda_pedido_cliente). Pero el problema es que hay un campo (Order_NO) que tiene muchas relaciones en una tabla. De acuerdo con mi código, obtengo solo el primer valor en la columna Order_No después de unir las dos tablas. Quiero mostrar el número de pedidos de cada artículo por fecha correspondiente.

 Customer Order Demand Table +-----------------------------+ | id | item | Date | |-----|----------|------------| | 1 | BLU | 7/10/2020 | | 2 | PM | 7/20/2020 | | 3 | BLU | 7/23/2020 | +-----------------------------+ Customer Order Table +---------------------------------------------------------+ | id | COD_id | Order_NO | Date | |-----|----------------------------------|----------------| | 1 | 1 | #100 | 7/10/2020 | | 2 | 1 | #130 | 7/10/2020 | | 3 | 2 | #200 | 7/20/2020 | | 4 | 3 | #500 | 7/23/2020 | +---------------------------------------------------------+ Expected Table +-----------------------------------------------+ | | Item | Date | Order_NO | |-----|----------|------------|-----------------| | 1 | BLU | 7/10/2020 | #100 /#130 | | 2 | PM | 7/20/2020 | #200 | | 3 | BLU | 7/23/2020 | #500 | +-----------------------------------------------+
 var url=[ 'http://test.smartapps.lk/rest/api/selectQuery?sessionId=' + SessionId + '&maxRows=10&query=select id, Item, Date from Customer_Order_demand &output=json' ].join(''); var url2=[ 'http://test.smartapps.lk/rest/api/selectQuery?sessionId=' + SessionId + '&maxRows=10&query=select id,Order_NO from Customer_Order &output=json' ].join(''); var responseID2 = UrlFetchApp.fetch(url); var responseID3 = UrlFetchApp.fetch(url2); var table1 = JSON.parse(responseID2.getContentText()); var table2 = JSON.parse(responseID3.getContentText()); var finalArray = []; for(var i in table1){ for(var j in table2){ //Joining two tables if(table1[i][0]==table2[j][0]){ // converting to json object var newObj = { "Item": table1[i][1], "Date":table1[i][2], "Order_NO": table2[j][1] }; finalArray.push(newObj); } } } return finalArray;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  • Reduzca la segunda tabla a un mapa :

     const table2map = table2.reduce( (mp,[codId,ordNo]) => mp.set(codId, mp.has(codId) ? [...mp.get(codId),ordNo] : [ordNo] ), new Map )
  • Asigne table1 a una matriz de objetos:

     const finalArr = table1.map( ([id,Item,Date]) => ({Item,Date, "Order_No": table2map.get(id).join()}) )
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!