13. april 2011 - 21:47Der er
8 kommentarer og 1 løsning
Lave en Sum if i en query - jeg fatter det simpelthen ikke!
Hej, Jeg har en linked table if Acces fra excel. Der har jeg lavet en query som ser nogenlunde sådan ud: (tabel data) Person Sales doc Type Pris Betaling xx xx xx xx yy yyyy yy yy zz xxxx zz zz
så har jeg en anden tabel (betaling) således: Person Sales doc betaling xx xxxx xxx
så vil jeg gerne have den ender således:
Person Sales doc Type Pris Betaling xx xx xx xx xxx (fra tabel betaling) yy yyyy yy yy zz xxxx zz zz
mit problem er at da sales doc i tabel er flere steder vil den automatisk kun se på sales doc og ikke sales doc OG person... så jeg ender med at både person xx og zz har fået xxx ibetaling!
Unfortunately the tables are linked to Excel, so I have no idea how to transfer the DB!
To wrap up: I have a query creating the following (DATA): Person Sales doc Type Pris Betaling JB 123 PP 100 LT 456 PO 200 LT 123 SF 300
And a table (betaling) Perosn Sales Doc Betaling JB 123 100 JB 789 200 LT 123
Then I like the query to return 100 from the betaling table (came from Person JB with sales doc 123 - these combined so it will leave person LT even though the sales doc is the same!!!) so the final query DATA will be: Person Sales doc Type Pris Betaling JB 123 PP 100 100 LT 456 PO 200 (blank) LT 123 SF 300 (blank)
SELECT tblData.Person, tblData.[Sales Doc], tblData.Type, tblData.Pris, Sum(tblBetaling.Betaling) AS SumOfBetaling FROM tblData LEFT JOIN tblBetaling ON (tblData.[Sales Doc] = tblBetaling.[Sales Doc]) AND (tblData.Person = tblBetaling.Person) GROUP BY tblData.Person, tblData.[Sales Doc], tblData.Type, tblData.Pris;
This is the result
Person Sales Doc Type Pris SumOfBetaling JB 123 PP 100 100 LT 123 SF 300 LT 456 PO 200
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.