Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mmani2334
Starting Member
2 Posts |
Posted - 2015-02-04 : 18:18:28
|
I am trying to write my first query for the statement below and I stuck. Any help would be greatly appreciated.I believe I would have to use a join for the three tables this query would have to look at?1. Get full part-details of all parts that are shipped to any project in LONDON. SupplierNo Name Status CityS1 SMITH 20 LONDONS2 JONES 10 PARISS3 BLAKE 30 PARISS4 CLARK 20 LONDONS5 ADAMS 30 ATHENSPartNo Name Color Weight CityP1 NUT RED 12 LONDONP2 BOLT GREEN 17 PARISP3 SCREW BLUE 17 ROMEP4 SCREW RED 14 LONDONP5 CAMERA BLUE 32 PARISP6 WRENCH RED 19 LONDONP7 C-O-G GREEN 12 ROMEProjectNo Name CityJ1 SORTER PARISJ2 PUNCH ROMEJ3 READER ATHENSJ4 CONSOLE ATHENSJ5 COLLATOR LONDONJ6 TERMINAL OSLOJ7 TAPE LONDONJ8 DRUM LONDONSupplierNo PartNo ProjectNo QuantityS1 P1 J1 200S1 P1 J4 700S1 P3 J1 450S1 P3 J2 210S1 P3 J3 700S2 P3 J4 509S2 P3 J5 600S2 P3 J6 400S2 P3 J7 812S3 P5 J6 750S3 P3 J2 215S3 P4 J1 512S3 P6 J2 313S4 P6 J3 314S4 P2 J6 250S4 P5 J5 179S4 P5 J2 513S5 P7 J4 145S5 P1 J5 269S5 P3 J7 874S5 P4 J4 476S5 P5 J4 529S5 P6 J4 318S5 P2 J4 619Thank you! javascript:insertsmilie('') |
|
jleitao
Posting Yak Master
100 Posts |
Posted - 2015-02-05 : 07:32:51
|
first you need to filter your projects by city London:select*from projects_table as prjwhere prj.city = 'LONDON'after that you can use the quantity table to make the rations between the tablesselect*from projects_table as prjLEFT JOIN quantity_table as qtt on prj.ProjectNo = qtt.ProjectNowhere prj.city = 'LONDON'Now, using the quantity table you can create the relation with the others tablesselect*from projects_table as prjLEFT JOIN quantity_table as qtt on prj.ProjectNo = qtt.ProjectNoLEFT JOIN supllier_table sup on qtt.SupplierNo = sup.SupplierNowhere prj.city = 'LONDON'If you understand the logic i think you can create alone the relation with the part_table.------------------------PS - Sorry my bad english |
|
|
|
|
|