I looked at the various answers here and did some experiments.
In particular, I am using MariaDB 10.1.
For the βsimpleβ thing, you can do what Robert D. suggested in his comment:
SELECT Price_Per_SqFt, (Price_Per_SqFt/2) AS col1, (SELECT col1 + 1) AS col2 FROM Items
If you use some aggregate function with an inner join, you cannot use this, but you can combine this approach with the inner join approach as follows (NB VAT = "sales tax" ... and NB in ββthe financial data field usually have 4 decimal places, I think it's historical ...)
SELECT invoices.invoiceNo, invoices.clientID, invoices.Date, invoices.Paid, invoicesWithSubtotal.Subtotal, ROUND( CAST( Subtotal * invoices.VATRate AS DECIMAL( 10, 4 )), 2 ) AS VAT, (SELECT VAT + Subtotal) AS Total FROM invoices INNER JOIN ( SELECT Sum( invoiceitems.Charge ) AS Subtotal, invoices.InvoiceNo FROM invoices INNER JOIN invoiceitems ON invoices.InvoiceNo = invoiceitems.InvoiceNo GROUP BY invoices.InvoiceNo ) invoicesWithSubtotal ON invoices.InvoiceNo = invoicesWithSubtotal.InvoiceNo
I wanted to use the above to create a View to list invoices with their subtotals, VAT and totals ... it turned out that MariaDB (and almost certainly MySQL) does not allow nesting in the FROM , but this is easy to solve by creating the first View , which lists InvoiceNo and Subtotal , and then makes a second View , which refers to the first. In terms of quality, I generally donβt know how to arrange this double << 22>.
mike rodent Oct 26 '17 at 17:50 2017-10-26 17:50
source share