Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select equivalent in MySQL

Tags:

mysql

In my app, I'm using MySQL and what I want to do is to get the equivalent of a certain grade. Like for example, I have a grade of 13, the equivalent of it is 5.0.

I have this type of table structure with data.

    `transmutation` table

    id      grade   equi
    1       0       5.0
    2       14      4.0

And it also come to my mind that I could do this.

    `transmutation` table

    id      grade       equi
    1       01-13       5.0
    2       14-26       4.0

For now, I have this simple syntax in getting equivalent and it's incomplete.

    SELECT equi from transmutation WHERE grade BETWEEN 0 AND 14 AND grade = 0;

Any ideas would be most appreciated.

like image 493
yowza Avatar asked Apr 16 '26 15:04

yowza


2 Answers

The simplest way would be to define your table like this:

transmutation table

id      gradeFrom   gradeTo  equi
1       0           13       5.0
2       14          26       4.0

And then:

SELECT equi FROM transmutation WHERE 13 BETWEEN gradeFrom and gradeTo
like image 192
eugenioy Avatar answered Apr 18 '26 04:04

eugenioy


Well, BETWEEN will not work in this scenario but if you have your table data in second format per post then you can do a simple = equality comparison like below provided that the grade column data format is same

SELECT equi from transmutation WHERE grade = '01-13';
like image 34
Rahul Avatar answered Apr 18 '26 04:04

Rahul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!