How can I update a column based on a calculation of other columns in a table?

I would like to give each player a rank / position based on the values of other columns, 1 being the best position. Each prize or penalty is worth a different amount. Can this be done in SQL and how would I go about putting this into a query? Here is the ratio that i… Read More How can I update a column based on a calculation of other columns in a table?

How can add brackets to each word of a string which contains multiple words on SQL?

For example, i have: string example = ‘word1,word2,word3,word4,word5’ How can i convert to something like this: string example = ‘[word1],[word2],[word3],[word4],[word5]’ >Solution : We can use a combination of REPLACE() and string concatenation: SELECT val, CONCAT(‘[‘, REPLACE(val, ‘,’, ‘],[‘) , ‘]’) AS output FROM yourTable; On MySQL 8+, we can use a regex replacement: SELECT val,… Read More How can add brackets to each word of a string which contains multiple words on SQL?

How to query for amount waived for every contract status?

I have 2 tables: Table 1 "contract" is as the following (sample only): contract_id contract_status 111 Active 122 Active 133 Finished 144 Active 155 Finished contract_status values are: Active and Finished Table 2 "ledger" is as the following (sample only): ledger_id contract_id ledger_status amount 1gh 111 WAIVED 450 2uk 111 PAID 0 2jz 111 WAIVED… Read More How to query for amount waived for every contract status?

SQL will output my query only if I alias my columns in my select statement… Not sure why

Alright this is my curiosity, my question is why… First this is the ERD to understand the tables and connections… Now my Query is supposed to "Provide a table that provides the region for each sales_rep along with their associated accounts. Your final table should include three columns: the region name, the sales rep name,… Read More SQL will output my query only if I alias my columns in my select statement… Not sure why