Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying records in table after join and group by a particular column

 
Ankit Tripathi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two tables which contain some data :

Table1 : abc


||entity_id| entity_title| cust_code| cust_acc_no ||


|| AB101Z | IND | 101Z | 1234 ||

|| AB101Z | PAK | 101Z | 1357 ||

|| CD101Y | IND | 101Y | 2468 ||

|| EF101X | IND | 101X | 3579 ||

|| JK201N | LKO | 201N | 5678 ||


Table2 : def

||entity_title| in_count| out_quant||


|| IND | 10 | 7 |

|| LKO | 7 | 7 |

|| PAK | 5 | 2 |


joined Table : abcdef

||entity_id| entity_title| cust_code||


|| AB101Z | INDPAK | 101Z |

|| CD101Y | INDPAK | 101Y |

|| EF101X | INDPAK | 101X |

I want to join tables abc and def which would be resultant in table abcdef.While joining both tables and records would be grouped by entity_title
The joining condition would be such that in_count!=out_count.
For ex. in such situation LKO as entity_title would not be part of resultant table and I need to replace the entity_title records with matching condition by a third record signifying a matched record,for ex. INDPAK is the replacement for both IND and PAK entities on which condition is satisfying.
I tried to come up with a solution but was not able to form a single query.Thanks in advance for any solution suggested.

 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Learn some SQL e.g. look at how to join tables and use a WHERE clause to filter your data e.g. ".. WHERE foo != bar ...". SQL is designed to provide a reasonably natural language for expressing queries, but you still need to put a little effort into learning the basics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic