Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How do I multiply an unsigned int by -1 on a MySQL SELECT?
Let us first create a table −
mysql> create table DemoTable -> ( -> Value int -> ); Query OK, 0 rows affected (0.80 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-------+ | Value | +-------+ | 10 | | 20 | | 100 | +-------+ 3 rows in set (0.00 sec)
Here is the query to multiply an unsigned int by -1 on a SELECT −
mysql> select cast(Value*-1 as signed) from DemoTable;
Output
This will produce the following output −
+--------------------------+ | cast(Value*-1 as signed) | +--------------------------+ | -10 | | -20 | | -100 | +--------------------------+ 3 rows in set (0.00 sec)
Advertisements
