Code:
SELECT Customers.schoolname, Orders.invoiceid, Orders.orderdate, products.ProductName, [Order Details].Quantity, Orders.postage, Orders.postagepaid, mailshots.mailshotname, mailshots.sellerrate, [Order Details].discount, Round([sellerrate]/100*[europaid],2) AS sellercut, [Quantity]*[UnitPrice]-[discount]+[postage] AS Sub, [Sub]-[postagepaid]-[sellercut] AS [Sub Total], products.UnitPrice, mailshots.taxrate, Round([sellercut]*[taxrate]/100,2) AS sellercuttax, mailshots.fixed, mailshots.variable, Round([fixed]*[taxrate]/100,2) AS fixedtax, Round([variable]*[taxrate]/100,2) AS variabletax, [Sub Total]-[sellercut]-[sellercuttax]-[fixed]-[fixedtax]-[variable]-[variabletax] AS Total, [UnitPrice]*[Quantity]-[discount] AS soldfor, [sellercut]+[sellercuttax]+[fixed]+[fixedtax]+[variable]+[variabletax] AS sellerfees, Orders.paymentmethod, mailshots.postagefee, Round([postage]*[postagefee]/100,2) AS ebaypostagefee, mailshots.paypalcharge, mailshots.paymentrate, Round(([soldfor]+[postage])*[paymentrate]/1000,2) AS paymentcharge, [paymentcharge]+[paypalcharge] AS paypalfees, products.printquantity, mailshots.invoicing, Orders.ordersource, 1.19 AS eurorate, Round([fixed]*[eurorate],2) AS fixedeuro, Round([fixedtax]*[eurorate],2) AS fixedtaxeuro, [fixedeuro]+[fixedtaxeuro] AS fixedeurototal, Round([variable]*[eurorate],2) AS variableeuro, Round([variabletax]*[eurorate],2) AS variabletaxeuro, [variableeuro]+[variabletaxeuro] AS variableeurototal, Round(([sellercut]+[sellercuttax])*[eurorate],2) AS sellercuttotaleuro, Round([soldfor]*[eurorate],2) AS soldforeuro, [sellercuttotal]+[eurovariabletotal]+[eurofixedtotal] AS totalfeeseuro, Orders.eurotrans, 0.84639 AS eurotoukrate, Round([newtranseuro]*[eurotoukrate],2) AS transuk, products.Pages, products.[Cover Pages], supplyorders.supplycost, supplyorders.supplyquantity, supplyorders.supplybought, products.colourink, products.blackink, [supplycost]/[supplyquantity] AS supplypercost, blackprint.blackcost, blackprint.blackquantity, [blackcost]/[blackquantity] AS blackcostper, colourprint.colourcost, colourprint.colourquantity, [colourcost]/[colourquantity] AS colourcostper, [Quantity]*([blackcostper]*[Pages]) AS blackprinttotal, [Quantity]*([colourcostper]*[Cover Pages]) AS colourprinttotal, [Quantity]*([supplypercost]*[Pages]) AS blackpagestotal, cello.cellocost, cello.celloquantity, [cellocost]/[celloquantity] AS cellounit, addresslabels.addresslabelcost, addresslabels.addresslabelquantity, burning.burningcost, burning.burningquantity, cdlabels.cdlabelscost, cdlabels.cdlabelsquantity, sellotape.sellotapecost, sellotape.sellotapequantity, wallets.walletcost, wallets.walletquantity, dvdcases.dvdcasecost, dvdcases.dvdcasequantity, [dvdcasecost]/[dvdcasequantity] AS dvdcaseunit, [walletcost]/[walletquantity] AS walletunit, [sellotapecost]/[sellotapequantity]/100 AS sellotapeunit, [cdlabelscost]/[cdlabelsquantity] AS cdlabelsunit, [burningcost]/[burningquantity] AS burningunit, [addresslabelcost]/[addresslabelquantity] AS addresslabelunit, [purchaseunit]+[cellounit]+[dvdcaseunit]+[burningunit]+[dvdprintunit]+[coverpagestotal]+[blackpagestotal]+[blackprinttotal]+[colourprinttotal]+[sellotapeunit]+[cdlabelsunit]+[addresslabelunit]+[walletunit]+[barcodeprint]+[cdlabelprintunit] AS productoverhead, [Cover Pages]*[colourcostper] AS dvdcoverunit, [supplypercost]*[Cover Pages] AS coverpagestotal, dvdprint.dvdprintcost, dvdprint.dvdprintquantity, [dvdprintcost]/[dvdprintquantity]/2 AS dvdprintunit, [blackpagestotal]+[coverpagestotal]+[blackprinttotal]+[colourprinttotal] AS inhouseprintcost, [blackcostper]/16 AS barcodeprint, [colour2cost]/[colour2quantity]/2 AS cdlabelprintunit, cdlabels.cdlabelsprint, colourprint2.colour2cost, colourprint2.colour2quantity, colourprint2.colour2bought, invoiceoverheads.invoiceoverheadcost, invoiceoverheads.invoicetype, [invoiceoverheadcost]/10000000000000000 AS invoicetotalcost, envelopes.envelopecost, envelopes.envelopequantity, envelopes.envelopebought, [envelopecost]/[envelopequantity] AS envelopepercost, [envelopepercost]+[invoicetotalcost] AS orderoverheads, [transuk]-[productoverhead]-[orderoverheads]-[postagepaid] AS profit, Purchase.orderref, Purchase.purchasequantity, Purchase.purchaseamount, [purchaseamount]/[purchasequantity] AS purchaseunit, Orders.postageeuro, [Order Details].europaid, [sellercut]+[sellercuttax] AS sellercuttotal, mailshots.eurovariable, Round([eurovariable]*[taxrate]/100,2) AS eurovariabletax, [eurovariable]+[eurovariabletax] AS eurovariabletotal, mailshots.eurofixed, Round([eurofixed]*[taxrate]/100,2) AS eurofixedtax, [eurofixed]+[eurofixedtax] AS eurofixedtotal, [totalfeeseuro]/[eurorate] AS totalfees, [europaid]+[europostage]-[totalfeeseuro] AS newtranseuro, mailshots.europostage, [Order Details].itemno
FROM mailshots INNER JOIN (Customers INNER JOIN (Purchase INNER JOIN (envelopes INNER JOIN (invoiceoverheads INNER JOIN (colourprint2 INNER JOIN (dvdprint INNER JOIN (dvdcases INNER JOIN (wallets INNER JOIN (sellotape INNER JOIN (cdlabels INNER JOIN (burning INNER JOIN (addresslabels INNER JOIN (cello INNER JOIN (colourprint INNER JOIN (blackprint INNER JOIN (supplyorders INNER JOIN ((Orders INNER JOIN [Order Details] ON Orders.invoiceid = [Order Details].OrderID) INNER JOIN products ON [Order Details].productid = products.ProductID) ON supplyorders.ID = products.paperused) ON blackprint.ID = products.blackink) ON colourprint.ID = products.colourink) ON cello.ID = products.celloused) ON addresslabels.ID = products.barcodelabel) ON burning.ID = products.burningused) ON cdlabels.ID = products.cdlabel) ON sellotape.ID = products.sellotape) ON wallets.ID = products.walletused) ON dvdcases.ID = products.dvdcase) ON dvdprint.ID = products.dvdprint) ON colourprint2.ID = products.colourink2) ON invoiceoverheads.ID = Orders.invoiceused) ON envelopes.ID = Orders.envelopeused) ON Purchase.purchaseno = products.purchaseused) ON Customers.customerid = Orders.customerid) ON mailshots.ID = Orders.ordersource
WHERE (((Orders.ordersource)=38) AND ((Orders.eurotrans)>0))
ORDER BY Orders.invoiceid DESC;
Here is the separate query which shows the count column I need. However I can't figure out to add in this functionality to the main code so I could calculate the postage paid divided by the count of items bought in all orders.