Format Player Names
A sports analytics company is preparing a dataset of cricket players for a new fantasy league. They need to standardize player names to ensure consistency.
Table: players
player_id(integer, PK)full_name(varchar(100))
Return the player_id and the full_name formatted such that the first letter of each word in the name is capitalized, and the rest of the letters are lowercase. The output should be ordered by player_id.
Handle NULL full_name values by returning NULL for the formatted name. Empty results are possible if the players table is empty. Ties in formatted names are handled by the player_id ordering.
Tables
CREATE TABLE players ( player_id integer PRIMARY KEY, full_name varchar(100) );
Example data
INSERT INTO players (player_id, full_name) VALUES (1, 'virat kohli'), (2, 'ROHIT SHARMA'), (3, 'sachin tendulkar'), (4, 'MS DHONI'), (5, 'sourav ganguly'), (6, 'rahul dravid'), (7, NULL), (8, 'yuvraj singh');
Your query is also checked on hidden datasets with different data.
Hints
-- Write your SQL query here
SELECT
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.