using a calculator in mysql

need to perform some maths operations while working on mysql ?
Do you use bc or some other application.

Here is how my friend Nir hacked mysql …

mysql> 816-528
ERROR 1064: You have an error in your SQL syntax near ‘816-528′ at line 1
mysql> select 816-528 from any_table_name;
| 288 |
| 288 |
| 288 |
+———+
834 rows in set (0.01 sec)
mysql> select distinct(816-528) from any_table_name;
+———–+
| (816-528) |
+———–+
| 288 |
+———–+
1 row in set (0.01 sec)
Bingo!

its good enough for +. - . *, / etc. you rock Nir.

Todays link : Google Ranking Factors

and BSE@7800 sad

5 Responses to “using a calculator in mysql”

  1. Vishal Says:

    Re:
    This is height of ‘bc’ :))
    If one is so fond of ‘bc’ on mysql he could could just type
    select operation ,where operation would be evaluated.

  2. Kunal Says:

    Re:
    try this..
    mysql> select mathematical_expression from dual;
    :)
    btw what is this google ranking factor ??

  3. smr Says:

    Re:
    “select operation”
    that looks like a feature… and what nir did was hacking…
    “from dual”
    some_database.dual doesn’t exist. must be some oracle stuff. ;)

    link is corrected now. some google heuristics for page ranking.

  4. Vishal Says:

    Re:
    Where is hacking in this????
    select ‘from’ a table returns all its tuples, the SQL query parser has the ability to evaluate expressions, and using distinct you rule out duplicates.

  5. kopos Says:

    about dual dual
    select from dual;

    is a sql query that operates on a dummy table ‘dual’ created in oracle just for the purposes other than data selection. one is the mathematical operation that you have ‘hacked’. other use is to return empty tuples to the user.

    My search indicates:
    From MySQL 4.1.0 on, you are allowed to specify DUAL as a dummy table name in situations where no tables are referenced:

    mysql> SELECT 1 + 1 FROM DUAL;
    -> 2

    DUAL is purely a compatibility feature. Some other servers require this syntax.

Leave a Reply