I have to create a table including a column named tax. The data values of that column are such as 20k, 15k, and so on. So I used varchar(10) data type for that column. But when I have to do calculation or comparison , (eg) to find the tax more than 15k, I have to use that as an int (tax>15). Is the correct way? Or is there any better way?
I consider to change the column name as “tax(k)”. But I didn’t because I want to keep the table as the original table. In the original table, the column name is just tax and the data values are 10k, 15k and so on.
Mysql – thesql data types: define as char but work as int
MySQL
Related Question
- Mysql – find and insert row to another table using thesql trigger
- MYSQL How to query to show data in separate columns from one field
- Database Design – Best Logical Structure for Different Entity Categories
- MySQL – Indexes deleted, reduced column size but table size increases
- MySQL Optimization – How to Optimize a Simple Query on a Large Table
- MySQL VARCHAR Datatype Accepting Integer Values – Explanation
Best Answer
If there is no specific requirement for you to store the data in that manner then you SHOULD change the datatype of the column and make it to INT or Decimal as per your requirement.( This would be a suggestible approach as you will need to do a lot of calculations and there is no inbuilt function to calculate 'K' values)
However if there is not way out, you can use a replace function to replace the 'K' with a space or '000' and use INT/DECIMAL function to convert the same for your calculations. Syntax would be something as below
OR