mysql sub-select work around?

JD Austin plug-discuss@lists.plug.phoenix.az.us
Wed, 05 Feb 2003 09:09:12 -0700


Mike Starke wrote:

>I know the new version of MySQL supports subselects,
>but I am just not ready for that upgrade. So here's my
>question:
>
>I have a table called 'idt' with two columns "unit" and "price".
>How can I get an equivalent SQL statement that will work in
>MySQL 3.23
>
>SELECT SUM
>        (
>	SELECT (idt.unit * idt.price) AS Sub_Total
>	FROM idt WHERE idt.myid = "1"
>	)  AS Total 
>	FROM idt
>
>v/r
>-Mike
>---------------------------------------------------
>PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
>To subscribe, unsubscribe, or to change  you mail settings:
>http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>  
>
Don't know if you need both total and subtotal but.. 
It's been awhile since I've used MySQL (Im an Oracle guy) but cant you do something like this? :

	SELECT (idt.unit * idt.price) AS Subtotal, SUM((idt.unit * idt.price)) AS Total
	FROM idt WHERE idt.myid = "1" group by (idt.unit * idt.price);