List:General Discussion« Previous MessageNext Message »
From:mos Date:December 19 2005 3:34pm
Subject:Re: How to Square a number?
View as plain text  
At 08:30 AM 12/19/2005, Peter Brawley wrote:
> >        Yes, it's a bit more complicated than that. I'm using an expression
> >so I don't want to have to repeat the whole expression all over again.
>
>What's wrong with CAST( POWER( <expr>, 2 ) AS SIGNED )?
>
>PB
>
>------

PB,
         Yes it looks like I'll have to use Power() after all. From a 
programming standpoint, I thought using a floating point function like 
Power on an integer was inefficient and makes it harder to read the 
exoression. But I'll give it a try. Thanks. I'm still not sure why the ** 
operator is not supported because it would reduce the amount of code 
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 
>>>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 
>> expression so I don't want to have to repeat the whole expression all 
>> 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 something 
>>> simple like:
>>> >select 3**2
>>> >but that produces a syntax error. I can use Pow(3,2) but that 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=1
>>
>>
>
>
>--
>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

Thread
How to Square a number?mos19 Dec
  • Re: How to Square a number?James Harvard19 Dec
    • Re: How to Square a number?mos19 Dec
      • Re: How to Square a number?Peter Brawley19 Dec
        • Re: How to Square a number?mos19 Dec
          • Re: How to Square a number?Elmar von Muralt19 Dec
            • Re: How to Square a number?mos19 Dec
  • Re: How to Square a number?SGreen19 Dec
  • Re: How to Square a number?Hugh Sasse19 Dec
RE: How to Square a number?SST - Adelaide)19 Dec
  • RE: How to Square a number?mos20 Dec
RE: How to Square a number?SST - Adelaide)20 Dec