
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Calculating byte values to megabyte (MB) in MySQL?
Here, we are taking BIGINT type, since it takes 8 byte signed integer. Let us first create a table with column as BIGINT type −
mysql> create table DemoTable2031 -> ( -> ByteValue bigint -> ); Query OK, 0 rows affected (1.17 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2031 values(1048576); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2031 values(1073741824); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2031;
This will produce the following output −
+------------+ | ByteValue | +------------+ | 1048576 | | 1073741824 | +------------+ 2 rows in set (0.00 sec)
Here is the query to calculate bytes to Megabyte (MB) −
mysql> select (ByteValue/(1024*1024)) as MB from DemoTable2031;
This will produce the following output −
+-----------+ | MB | +-----------+ | 1.0000 | | 1024.0000 | +-----------+ 2 rows in set (0.00 sec)
- Related Articles
- Calculating power of a number in MySQL?
- Difference between Megabyte and Gigabyte
- Convert byte primitive type to Byte object in Java
- Java Program to Calculate Sum of Two Byte Values Using Type Casting
- Calculating percentage in a MySQL query and round off the result
- MySQL BIT_LENGTH() function is multi-byte safe or not?
- How to count distinct values in MySQL?
- How to count null values in MySQL?
- Convert byte to String in Java
- Calculating time taken to type words in JavaScript
- BOOLEAN or TINYINT to store values in MySQL?
- Sort certain values to the top in MySQL?
- Append special characters to column values in MySQL
- How to concatenate byte array in java?
- How to concat Values in MySQL Query and to handle Null values as well?

Advertisements