From: David (SST - Adelaide) Logan Date: December 19 2005 9:30pm Subject: RE: How to Square a number? List-Archive: http://lists.mysql.com/mysql/193033 Message-Id: <2E5067E0651BCD4FB7133D3F8B854FEB09B75B@NWIEXC01.asiapacific.cpqcorp.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Why not then use user variables? eg. select @a:=3D((col1+col2+col3)/col4), @b:=3D((col5+col6+col7)/col8), pow(@a,2), pow(@b,2) ... table1 Regards David Logan Database Administrator HP Managed Services 148 Frome Street, Adelaide 5000 Australia +61 8 8408 4273 - Work +61 417 268 665 - Mobile +61 8 8408 4259 - Fax -----Original Message----- From: mos [mailto:mos99@stripped]=20 Sent: Tuesday, 20 December 2005 7:40 AM To: Elmar von Muralt Cc: mysql@stripped Subject: Re: How to Square a number? At 02:32 PM 12/19/2005, Elmar von Muralt wrote: >Mike, > >How about: > >temp1 =3D [Expression] >temp2 =3D temp1 * temp1 > >This should be quick enough, assuming tempN are cast as integers > >Elmar Nope, not quite. The expression is an expression based on columns in the table, as in: select ((col1+col2+col3)/col4), ((col5+col6+col7)/col8) ... table1 So it looks like I'll have to use Power(num,exp) after all to square these=20 expressions. Mike >mos wrote: > >>At 08:30 AM 12/19/2005, Peter Brawley wrote: >> >>> > Yes, it's a bit more complicated than that. I'm using an=20 >>> expression >>> >so I don't want to have to repeat the whole expression all over again. >>> >>>What's wrong with CAST( POWER( , 2 ) AS SIGNED )? >>> >>>PB >>> >>>------ >> >> >>PB, >> Yes it looks like I'll have to use Power() after all. From a=20 >> programming standpoint, I thought using a floating point function like=20 >> Power on an integer was inefficient and makes it harder to read the=20 >> exoression. But I'll give it a try. Thanks. I'm still not sure why the=20 >> ** operator is not supported because it would reduce the amount of code=20 >> considerably (I have to square quite a few numbers). Oh well. :( >> >>Mike >> >> >>>mos wrote: >>> >>>>At 05:43 PM 12/18/2005, James Harvard wrote: >>>> >>>>>Maybe I'm missing something, but can't you just multiply the number by=20 >>>>>itself? >>>>> >>>>>select (3 * 3); >>>>> >>>>>select (int_col * int_col) as squared from table_name; >>>>> >>>>>James H >>>> >>>> >>>> >>>> >>>> >>>>James, >>>> Yes, it's a bit more complicated than that. I'm using an=20 >>>> expression so I don't want to have to repeat the whole expression all=20 >>>> over again. >>>> >>>>Mike >>>> >>>> >>>> >>>> >>>>>At 5:36 pm -0600 18/12/05, mos wrote: >>>>> >How do I square a number in MySQL 4.1? I thought it would be=20 >>>>> something simple like: >>>>> >select 3**2 >>>>> >but that produces a syntax error. I can use Pow(3,2) but that=20 >>>>> produces a float. Is there a Square function? >>>>> >>>>>-- >>>>>MySQL General Mailing List >>>>>For list archives: http://lists.mysql.com/mysql >>>>>To unsubscribe: >>>>>http://lists.mysql.com/mysql?unsub=3Dmos99@stripped >>>> >>>> >>> >>> >>>-- >>>No virus found in this outgoing message. >>>Checked by AVG Free Edition. >>>Version: 7.1.371 / Virus Database: 267.14.1/206 - Release Date: 12/16/2005 >> >> --=20 MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: = http://lists.mysql.com/mysql?unsub=3Ddavid.logan@stripped