I have been working on a project which analyze credit rate from different bank.
I have a simple table structured like below
`id` varchar(255) DEFAULT NULL,
`credit_name` varchar(255) DEFAULT NULL,
`credit_name2` varchar(255) DEFAULT NULL,
`rate_home` float DEFAULT NULL,
`rate_vehicle` float NOT NULL,
`rate_need` float NOT NULL,
`bankname` float NOT NULL,
Example input below:
id | credit_name | credit_name2 | rate_home | rate_vehicle | rate_need | bankname |
---|---|---|---|---|---|---|
1 | Take Me | Take Me 2 | 10 | 5 | 15 | Bank A |
2 | Take Me | Take Me 2 | 15 | 20 | 8 | Bank B |
3 | Take Me | Take Me 2 | 20 | 25 | 45 | Bank C |
4 | Take Me | Take Me 2 | 35 | 12 | 4 | Bank D |
5 | GET Me | GET Me 2 | 11 | 6 | 12 | Bank A |
6 | GET Me | GET Me 2 | 15 | 45 | 23 | Bank B |
7 | GET Me | GET Me 2 | 22 | 67 | 35 | Bank C |
8 | GET Me | GET Me 2 | 36 | 6 | 7 | Bank D |
Example output:
rate_home | rate_vehicle | rate_need |
---|---|---|
35 from bank d | 25 from bank c | 45 from bank c |
36 from bank d | 67 from bank c | 45 from bank c |
The output may be a wrong structure bu forgive my lack of experience.
Every 4 rows must be compared in itself
I use BS4 TO fetch data , MYSQL to store the data and PYTHON to process data
3
Answers
this can be done in sql side
Not an easy solution but you can use union for the 3 columns , then use an outer query to get the 1 result for each column:
https://dbfiddle.uk/0WlUbzT1
Note this doesn’t handle ties
Edit.The op needs the max values for each credit_name group. The above query helped the op and it’s a slight modification from
Slava Rozhnev answer
You can solve this in next way:
sqlize
Result: