Change mysql real number type column to percent (%) type and output it

Asked 2 years ago, Updated 2 years ago, 41 views

There is a table like the following picture in the table called Basic1W

About row with year=2013, month=1, day=1

ChangeOP (1w) to Change Sales (1W) column expressed as a real number as % (0.11->11%)

I would appreciate it if you could let me know the query that prints the entire table after changing it.

mysql

2022-09-22 18:05

1 Answers

Multiply the value by 100 and round it to the right... I think it'll work. -_-;

/* Multiply the value of the ChangeOP (1W) column (0 if not) by 100 and round to 1 decimal place, followed by the letter '%'. */
SELECT CAST(ROUND(100 * IFNULL(`ChangeOP(1W)`, 0), 1)) + '%' AS ChangeOP1wpercent
FROM Basic1W
WHERE year = 2013 AND month = 1 AND day = 1

You can calculate it right away from the time you query it like this, but you can calculate it at the time you write this value. Is there anything that can't be solved with this?

+ By the way, I don't think it's a good idea to put parentheses in the column names. There are times when SQL grammar uses parentheses. (As you can see.))


2022-09-22 18:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.