Database schema:

CREATE TABLE city (
	id INTEGER NOT NULL -- example: ['2', '1'],
	city_name TEXT DEFAULT NULL -- example: ['Barcelona', 'London'],
	PRIMARY KEY (id)
)


CREATE TABLE competitor_event (
	event_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	competitor_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	medal_id INTEGER DEFAULT NULL -- example: ['1', '4'],
	CONSTRAINT fk_competitor_event_games_competitor FOREIGN KEY(competitor_id) REFERENCES games_competitor (id),
	CONSTRAINT fk_competitor_event_event FOREIGN KEY(event_id) REFERENCES event (id),
	CONSTRAINT fk_competitor_event_medal FOREIGN KEY(medal_id) REFERENCES medal (id)
)


CREATE TABLE event (
	id INTEGER NOT NULL -- example: ['2', '1'],
	sport_id INTEGER DEFAULT NULL -- example: ['9', '33'],
	event_name TEXT DEFAULT NULL -- example: ["Judo Men's Extra-Lightweight", "Basketball Men's Basketball"],
	PRIMARY KEY (id), 
	CONSTRAINT fk_event_sport FOREIGN KEY(sport_id) REFERENCES sport (id)
)


CREATE TABLE games (
	id INTEGER NOT NULL -- example: ['2', '1'],
	games_year INTEGER DEFAULT NULL -- example: ['2012', '1992'],
	games_name TEXT DEFAULT NULL -- example: ['1992 Summer', '2012 Summer'],
	season TEXT DEFAULT NULL -- example: ['Winter', 'Summer'],
	PRIMARY KEY (id)
)


CREATE TABLE games_city (
	games_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	city_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	CONSTRAINT fk_games_city_city FOREIGN KEY(city_id) REFERENCES city (id),
	CONSTRAINT fk_games_city_games FOREIGN KEY(games_id) REFERENCES games (id)
)


CREATE TABLE games_competitor (
	id INTEGER NOT NULL -- example: ['2', '1'],
	games_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	person_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	age INTEGER DEFAULT NULL -- example: ['23', '24'],
	PRIMARY KEY (id), 
	CONSTRAINT fk_games_competitor_games FOREIGN KEY(games_id) REFERENCES games (id),
	CONSTRAINT fk_games_competitor_person FOREIGN KEY(person_id) REFERENCES person (id)
)


CREATE TABLE medal (
	id INTEGER NOT NULL -- example: ['2', '1'],
	medal_name TEXT DEFAULT NULL -- example: ['Gold', 'Silver'],
	PRIMARY KEY (id)
)


CREATE TABLE noc_region (
	id INTEGER NOT NULL -- example: ['2', '1'],
	noc TEXT DEFAULT NULL -- example: ['AFG', 'AHO'],
	region_name TEXT DEFAULT NULL -- example: ['Afghanistan', 'Netherlands Antilles'],
	PRIMARY KEY (id)
)


CREATE TABLE person (
	id INTEGER NOT NULL -- example: ['2', '1'],
	full_name TEXT DEFAULT NULL -- example: ['A Dijiang', 'A Lamusi'],
	gender TEXT DEFAULT NULL -- example: ['M', 'F'],
	height INTEGER DEFAULT NULL -- example: ['180', '170'],
	weight INTEGER DEFAULT NULL -- example: ['60', '80'],
	PRIMARY KEY (id)
)


CREATE TABLE person_region (
	person_id INTEGER DEFAULT NULL -- example: ['2', '1'],
	region_id INTEGER DEFAULT NULL -- example: ['42', '56'],
	CONSTRAINT fk_person_region_person FOREIGN KEY(person_id) REFERENCES person (id),
	CONSTRAINT fk_person_region_noc_region FOREIGN KEY(region_id) REFERENCES noc_region (id)
)


CREATE TABLE sport (
	id INTEGER NOT NULL -- example: ['2', '1'],
	sport_name TEXT DEFAULT NULL -- example: ['Aeronautics', 'Alpine Skiing'],
	PRIMARY KEY (id)
)

Question: How many Olympic events did Michael Phelps II join in total? Find the percentage of the events where he won a gold medal.
Evidence: DIVIDE(COUNT(event_id where medal_name = 'Gold'), COUNT(event_id)) as percentage where full_name = 'Michael Fred Phelps, II';

SQL:
SELECT COUNT(T3.event_id) , CAST(COUNT(CASE WHEN T4.id = '1' THEN 1 ELSE NULL END) AS REAL) * 100 / COUNT(T4.id) FROM person AS T1 INNER JOIN games_competitor AS T2 ON T1.id = T2.person_id INNER JOIN competitor_event AS T3 ON T2.id = T3.competitor_id INNER JOIN medal AS T4 ON T3.medal_id = T4.id WHERE T1.full_name = 'Michael Fred Phelps, II'