SELECT CAST(SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END), 0) FROM customers

eur_count = customers[customers["Currency"] == "EUR"].shape[0]
czk_count = customers[customers["Currency"] == "CZK"].shape[0]
result = float(eur_count) / czk_count


SELECT T1.CustomerID FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM' AND SUBSTR(T2.Date, 1, 4) = '2012' GROUP BY T1.CustomerID ORDER BY SUM(T2.Consumption) ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")
filtered_df = merged_df[(merged_df["Segment"] == "LAM") & (merged_df["Date"].str[:4] == "2012")]
grouped_df = filtered_df.groupby("CustomerID")["Consumption"].sum()
result = grouped_df.idxmin()


SELECT AVG(T3.TotalConsumption) / NULLIF(12, 0) FROM (SELECT SUM(T2.Consumption) AS TotalConsumption FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME' GROUP BY T1.CustomerID) AS T3

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")
filtered_df = merged_df[(merged_df["Segment"] == "SME") & (merged_df["Date"].str[:4] == '2013')]
grouped_df = filtered_df.groupby("CustomerID")["Consumption"].sum()
result = grouped_df.mean() / 12


SELECT SUBSTR(T2.Date, 1, 4) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' GROUP BY SUBSTR(T2.Date, 1, 4) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")
filtered_df = merged_df[merged_df["Currency"] == "CZK"]
filtered_df["Year"] = filtered_df["Date"].str[:4]
grouped_df = filtered_df.groupby("Year")["Consumption"].sum()
result = grouped_df.idxmax()


SELECT SUBSTR(T2.Date, 5, 2) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE SUBSTR(T2.Date, 1, 4) = '2013' AND T1.Segment = 'SME' GROUP BY SUBSTR(T2.Date, 5, 2) ORDER BY SUM(T2.Consumption) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")
filtered_df = merged_df[(merged_df["Segment"] == "SME") & (merged_df["Date"].str[:4] == "2013")]
grouped_df = filtered_df.groupby(filtered_df["Date"].str[4:6])["Consumption"].sum()
result = grouped_df.idxmax()


SELECT CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) - CAST(SUM(CASE WHEN T1.Segment = 'SME' THEN T2.Consumption ELSE 0 END) AS REAL) / NULLIF(COUNT(T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' AND T2.Consumption = (SELECT MIN(Consumption) FROM yearmonth) AND T2.Date::text BETWEEN '201301' AND '201312'

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")

filtered_df = merged_df[
(merged_df["Currency"] == "CZK") &
(merged_df["Date"].between("201301", "201312"))
]

min_consumption = filtered_df["Consumption"].min()

filtered_df = filtered_df[filtered_df["Consumption"] == min_consumption]

sme_consumption = filtered_df[filtered_df["Segment"] == "SME"]["Consumption"].sum()
lam_consumption = filtered_df[filtered_df["Segment"] == "LAM"]["Consumption"].sum()
kam_consumption = filtered_df[filtered_df["Segment"] == "KAM"]["Consumption"].sum()

sme_count = filtered_df[filtered_df["Segment"] == "SME"]["CustomerID"].nunique()
lam_count = filtered_df[filtered_df["Segment"] == "LAM"]["CustomerID"].nunique()
kam_count = filtered_df[filtered_df["Segment"] == "KAM"]["CustomerID"].nunique()

sme_avg = sme_consumption / sme_count if sme_count > 0 else 0
lam_avg = lam_consumption / lam_count if lam_count > 0 else 0
kam_avg = kam_consumption / kam_count if kam_count > 0 else 0

result = (sme_avg - lam_avg, lam_avg - kam_avg, kam_avg - sme_avg)


SELECT CAST((SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'SME' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'LAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0), CAST(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2013%' THEN T2.Consumption ELSE 0 END) - SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T1.Segment = 'KAM' AND T2.Date LIKE '2012%' THEN T2.Consumption ELSE 0 END), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'EUR'

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")

filtered_df = merged_df[merged_df["Currency"] == "EUR"]

sme_2012 = filtered_df[(filtered_df["Segment"] == "SME") & (filtered_df["Date"].str.startswith("2012"))]["Consumption"].sum()
sme_2013 = filtered_df[(filtered_df["Segment"] == "SME") & (filtered_df["Date"].str.startswith("2013"))]["Consumption"].sum()
sme_percentage_increase = round(((sme_2013 - sme_2012) / sme_2012) * 100, 3) if sme_2012 != 0 else None

lam_2012 = filtered_df[(filtered_df["Segment"] == "LAM") & (filtered_df["Date"].str.startswith("2012"))]["Consumption"].sum()
lam_2013 = filtered_df[(filtered_df["Segment"] == "LAM") & (filtered_df["Date"].str.startswith("2013"))]["Consumption"].sum()
lam_percentage_increase = round(((lam_2013 - lam_2012) / lam_2012) * 100, 3) if lam_2012 != 0 else None

kam_2012 = filtered_df[(filtered_df["Segment"] == "KAM") & (filtered_df["Date"].str.startswith("2012"))]["Consumption"].sum()
kam_2013 = filtered_df[(filtered_df["Segment"] == "KAM") & (filtered_df["Date"].str.startswith("2013"))]["Consumption"].sum()
kam_percentage_increase = round(((kam_2013 - kam_2012) / kam_2012) * 100, 3) if kam_2012 != 0 else None

result = (sme_percentage_increase, lam_percentage_increase, kam_percentage_increase)


SELECT SUM(CASE WHEN Currency = 'CZK' THEN 1 ELSE 0 END) - SUM(CASE WHEN Currency = 'EUR' THEN 1 ELSE 0 END) FROM customers WHERE Segment = 'SME'

sme_customers = customers[customers["Segment"] == "SME"]
czk_count = (sme_customers["Currency"] == "CZK").sum()
eur_count = (sme_customers["Currency"] == "EUR").sum()
result = czk_count - eur_count


SELECT CAST(COUNT(DISTINCT CASE WHEN T2.Consumption > 46.73 THEN T1.CustomerID ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T1.CustomerID), 0) FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'LAM'

merged_df = pd.merge(customers, yearmonth, on="CustomerID", how="inner")
lam_customers = merged_df[merged_df["Segment"] == "LAM"]
consumed_more_than_46_73 = lam_customers[lam_customers["Consumption"] > 46.73]["CustomerID"].nunique()
total_lam_customers = lam_customers["CustomerID"].nunique()
result = (consumed_more_than_46_73 / total_lam_customers) * 100


SELECT CAST(SUM(CASE WHEN Consumption > 528.3 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(CustomerID), 0) FROM yearmonth WHERE Date = '201202'

filtered_df = yearmonth[yearmonth["Date"] == '201202']
count_above_528_3 = (filtered_df["Consumption"] > 528.3).sum()
total_customers = filtered_df["CustomerID"].count()
result = (count_above_528_3 / total_customers) * 100


SELECT SUM(CAST(Consumption AS float)) FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2012' GROUP BY SUBSTR(Date, 5, 2) ORDER BY SUM(Consumption) DESC NULLS LAST LIMIT 1

yearmonth["Year"] = yearmonth["Date"].str[:4]
yearmonth["Month"] = yearmonth["Date"].str[4:6]

filtered_df = yearmonth[yearmonth["Year"] == "2012"]

grouped_df = filtered_df.groupby("Month")["Consumption"].sum()

result = grouped_df.max()

result = round(result, 1)


SELECT T3.Description FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Date = '201309'

merged_df_1 = pd.merge(transactions_1k, yearmonth, left_on="CustomerID", right_on="CustomerID", how="inner")
merged_df_2 = pd.merge(merged_df_1, products, left_on="ProductID", right_on="ProductID", how="inner")
filtered_df = merged_df_2[merged_df_2["Date_y"] == '201309']
result = filtered_df["Description"]


SELECT DISTINCT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE CAST(T1.Date AS VARCHAR) LIKE '2012-08-%'

merged_df = pd.merge(transactions_1k, gasstations, left_on="GasStationID", right_on="GasStationID", how="inner")
filtered_df = merged_df[merged_df["Date"].str.startswith("2012-08")]
result = filtered_df["Country"].unique()


SELECT DISTINCT T3.Description FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID INNER JOIN products AS T3 ON T1.ProductID = T3.ProductID WHERE T2.Country = 'CZE'

merged_df_1 = pd.merge(transactions_1k, gasstations, on="GasStationID", how="inner")
merged_df_2 = pd.merge(merged_df_1, products, on="ProductID", how="inner")
filtered_df = merged_df_2[merged_df_2["Country"] == "CZE"]
result = filtered_df["Description"].unique()


SELECT DISTINCT T1.Time FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.ChainID = 11

merged_df = pd.merge(transactions_1k, gasstations, left_on="GasStationID", right_on="GasStationID", how="inner")
filtered_df = merged_df[merged_df["ChainID"] == 11]
result = filtered_df["Time"].unique()


SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.Country = 'CZE' AND TO_CHAR(CAST(T1.Date AS TIMESTAMP), 'YYYY') >= '2012'

merged_df = pd.merge(transactions_1k, gasstations, left_on="GasStationID", right_on="GasStationID", how="inner")
filtered_df = merged_df[(merged_df["Country"] == "CZE") & (pd.to_datetime(merged_df["Date"]).dt.year >= 2012)]
result = filtered_df["TransactionID"].count()


SELECT COUNT(T1.TransactionID) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-26' AND T1.Time BETWEEN '08:00:00' AND '09:00:00' AND T2.Country = 'CZE'

merged_df = pd.merge(transactions_1k, gasstations, on="GasStationID", how="inner")
filtered_df = merged_df[(merged_df["Date"] == "2012-08-26") & (merged_df["Time"] >= "08:00:00") & (merged_df["Time"] <= "09:00:00") & (merged_df["Country"] == "CZE")]
result = len(filtered_df)


SELECT T2.Country FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.Date = '2012-08-24' AND T1.Price = '548.4'

merged_df = pd.merge(transactions_1k, gasstations, on="GasStationID", how="inner")
filtered_df = merged_df[(merged_df["Date"] == "2012-08-24") & (merged_df["Price"] == 548.4)]
result = filtered_df["Country"].iloc[0]


SELECT CAST(COUNT(DISTINCT CASE WHEN T2.Currency = 'EUR' THEN T1.CustomerID ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T1.CustomerID), 0) FROM transactions_1k AS T1 INNER JOIN customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Date = '2012-08-25'

merged_df = pd.merge(transactions_1k, customers, on="CustomerID", how="inner")
filtered_df = merged_df[merged_df["Date"] == "2012-08-25"]
eur_customers = filtered_df[filtered_df["Currency"] == "EUR"]["CustomerID"].nunique()
total_customers = filtered_df["CustomerID"].nunique()
result = (eur_customers / total_customers) * 100


SELECT CAST(SUM(CASE WHEN Country = 'SVK' AND Segment = 'Premium' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Country = 'SVK' THEN 1 ELSE 0 END), 0) FROM gasstations

total_svk = gasstations[gasstations["Country"] == "SVK"]
premium_count = total_svk[total_svk["Segment"] == "Premium"].shape[0]
result = (premium_count / total_svk.shape[0]) * 100


SELECT SUM(T1.Price), SUM(CASE WHEN CAST(T1.Date AS VARCHAR) LIKE '2012-08%' THEN T1.Price ELSE 0 END) FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T1.CustomerID = '38508'

merged_df = pd.merge(transactions_1k, gasstations, left_on="GasStationID", right_on="GasStationID", how="inner")
filtered_df = merged_df[merged_df["CustomerID"] == 38508]
total_spent = filtered_df["Price"].sum()
august_spent = filtered_df[filtered_df["Date"].str.startswith("2012-08")]["Price"].sum()
result = (total_spent, august_spent)


SELECT T2.Consumption FROM transactions_1k AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Price / NULLIF(T1.Amount, 0) > 29.00 AND T1.ProductID = 5 AND T2.Date = '201208'

merged_df = pd.merge(transactions_1k, yearmonth, on="CustomerID", how="inner")

merged_df = merged_df[merged_df["Amount"] > 0]

merged_df["Price_per_unit"] = merged_df["Price"] / merged_df["Amount"]

filtered_df = merged_df[
(merged_df["Price_per_unit"] > 29.00) &
(merged_df["ProductID"] == 5) &
(merged_df["Date_y"] == "201208")
]

filtered_df = filtered_df.drop_duplicates(subset=["Consumption"])

result = filtered_df["Consumption"].tolist()


SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.first_name = 'Angela' AND T1.last_name = 'Sanders'

merged_df = pd.merge(member, major, left_on="link_to_major", right_on="major_id", how="inner")
filtered_df = merged_df[(merged_df["first_name"] == "Angela") & (merged_df["last_name"] == "Sanders")]
result = filtered_df["major_name"].iloc[0]


SELECT T1.event_name FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event GROUP BY T1.event_id HAVING COUNT(T2.link_to_event) > 20 EXCEPT SELECT T1.event_name FROM event AS T1 WHERE T1.type = 'Fundraiser'

merged_df = pd.merge(event, attendance, left_on="event_id", right_on="link_to_event", how="inner")

grouped_df = merged_df.groupby("event_id").filter(lambda x: len(x) > 20)

non_fundraiser_events = event[event["type"] != "Fundraiser"]

filtered_df = grouped_df[grouped_df["event_id"].isin(non_fundraiser_events["event_id"])]

result = filtered_df["event_name"].unique().tolist()


SELECT T2.amount FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Vice President'

merged_df = pd.merge(member, income, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df[merged_df["position"] == "Vice President"]
result = filtered_df["amount"].sum()


SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN zip_code AS T2 ON T1.zip = T2.zip_code WHERE T2.state = 'Illinois'

merged_df = pd.merge(member, zip_code, left_on="zip", right_on="zip_code", how="inner")
filtered_df = merged_df[merged_df["state"] == "Illinois"]
result = filtered_df[["first_name", "last_name"]]


SELECT T3.approved FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' AND T1.event_date LIKE '2019-10-08%'

merged_df1 = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
merged_df2 = pd.merge(merged_df1, expense, left_on="budget_id", right_on="link_to_budget", how="inner")
filtered_df = merged_df2[(merged_df2["event_name"] == "October Meeting") & (merged_df2["event_date"].str.startswith("2019-10-08"))]
result = filtered_df["approved"]


SELECT AVG(T2.cost) FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.last_name = 'Allen' AND T1.first_name = 'Elijah' AND (SUBSTR(T2.expense_date, 6, 2) = '09' OR SUBSTR(T2.expense_date, 6, 2) = '10')

merged_df = pd.merge(member, expense, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df[
(merged_df["last_name"] == "Allen") &
(merged_df["first_name"] == "Elijah") &
(merged_df["expense_date"].str[5:7].isin(["09", "10"]))
]
result = filtered_df["cost"].mean()


SELECT SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2019' THEN T2.spent ELSE 0 END) - SUM(CASE WHEN SUBSTR(T1.event_date, 1, 4) = '2020' THEN T2.spent ELSE 0 END) AS num FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event

merged_df = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")

merged_df["spent"] = pd.to_numeric(merged_df["spent"], errors="coerce")

merged_df["Year"] = merged_df["event_date"].str[:4]

spent_2019 = merged_df.loc[merged_df["Year"] == "2019", "spent"].sum()
spent_2020 = merged_df.loc[merged_df["Year"] == "2020", "spent"].sum()

result = (spent_2019 - spent_2020).round(2)


SELECT notes FROM income WHERE source = 'Fundraising' AND date_received = '2019-09-14'

result = income[(income["source"] == "Fundraising") & (income["date_received"] == "2019-09-14")]["notes"]


SELECT T2.department FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.position = 'President'

merged_df = pd.merge(member, major, left_on="link_to_major", right_on="major_id", how="inner")
filtered_df = merged_df[merged_df["position"] == "President"]
result = filtered_df["department"]


SELECT T2.date_received FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Connor' AND T1.last_name = 'Hilton' AND T2.source = 'Dues'

merged_df = pd.merge(member, income, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df[(merged_df["first_name"] == "Connor") & (merged_df["last_name"] == "Hilton") & (merged_df["source"] == "Dues")]
result = filtered_df["date_received"]


SELECT CAST(SUM(CASE WHEN T2.event_name = 'Yearly Kickoff' THEN T1.amount ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN T2.event_name = 'October Meeting' THEN T1.amount ELSE 0 END), 0) FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' AND T2.type = 'Meeting'

merged_df = pd.merge(budget, event, left_on="link_to_event", right_on="event_id", how="inner")
filtered_df = merged_df[(merged_df["category"] == "Advertisement") & (merged_df["type"] == "Meeting")]
yearly_kickoff_sum = filtered_df[filtered_df["event_name"] == "Yearly Kickoff"]["amount"].sum()
october_meeting_sum = filtered_df[filtered_df["event_name"] == "October Meeting"]["amount"].sum()
result = yearly_kickoff_sum / october_meeting_sum


SELECT SUM(cost) FROM expense WHERE expense_description = 'Pizza'

filtered_df = expense[expense["expense_description"] == "Pizza"]
result = filtered_df["cost"].sum()


SELECT T2.major_name FROM member AS T1 INNER JOIN major AS T2 ON T1.link_to_major = T2.major_id WHERE T1.phone = '809-555-3360'

merged_df = pd.merge(member, major, left_on="link_to_major", right_on="major_id", how="inner")
filtered_df = merged_df[merged_df["phone"] == "809-555-3360"]
result = filtered_df["major_name"].iloc[0]


SELECT COUNT(T2.link_to_member) FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'Women''s Soccer'

merged_df = pd.merge(event, attendance, left_on="event_id", right_on="link_to_event", how="inner")
filtered_df = merged_df[merged_df["event_name"] == "Women's Soccer"]
result = filtered_df["link_to_member"].count()


SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T2.status = 'Closed' ORDER BY T1.spent / NULLIF(T1.amount, 0) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(budget, event, left_on="link_to_event", right_on="event_id", how="inner")
closed_events_df = merged_df[merged_df["status"] == "Closed"]
closed_events_df["spend_to_budget_ratio"] = closed_events_df["spent"] / closed_events_df["amount"]
highest_ratio_event = closed_events_df.sort_values(by="spend_to_budget_ratio", ascending=False).iloc[0]
result = highest_ratio_event["event_name"]


SELECT T1.first_name, T1.last_name FROM member AS T1 INNER JOIN attendance AS T2 ON T1.member_id = T2.link_to_member GROUP BY T1.member_id, T1.first_name, T1.last_name HAVING COUNT(T2.link_to_event) > 7

merged_df = pd.merge(member, attendance, left_on="member_id", right_on="link_to_member", how="inner")
grouped_df = merged_df.groupby("link_to_member").size().reset_index(name='event_count')
filtered_df = grouped_df[grouped_df["event_count"] > 7]
result = member[member["member_id"].isin(filtered_df["link_to_member"])][["first_name", "last_name"]]


SELECT T4.first_name, T4.last_name FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget INNER JOIN member AS T4 ON T3.link_to_member = T4.member_id WHERE T1.event_name = 'Yearly Kickoff'

merged_df1 = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
merged_df2 = pd.merge(merged_df1, expense, left_on="budget_id", right_on="link_to_budget", how="inner")
merged_df3 = pd.merge(merged_df2, member, left_on="link_to_member", right_on="member_id", how="inner")
filtered_df = merged_df3[merged_df3["event_name"] == "Yearly Kickoff"]
result = filtered_df[["first_name", "last_name"]]


SELECT source FROM income WHERE date_received BETWEEN '2019-09-01' AND '2019-09-30' ORDER BY source DESC NULLS LAST LIMIT 1

filtered_df = income[(income["date_received"] >= '2019-09-01') & (income["date_received"] <= '2019-09-30')]
result = filtered_df.sort_values(by="source", ascending=False).iloc[0]["source"]


SELECT COUNT(T2.member_id) FROM major AS T1 INNER JOIN member AS T2 ON T1.major_id = T2.link_to_major WHERE T1.major_name = 'Physics Teaching'

merged_df = pd.merge(major, member, left_on="major_id", right_on="link_to_major", how="inner")
filtered_df = merged_df[merged_df["major_name"] == "Physics Teaching"]
result = filtered_df["member_id"].count()


SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T1.link_to_event = T2.event_id WHERE T1.category = 'Advertisement' ORDER BY T1.spent DESC NULLS LAST LIMIT 1

merged_df = pd.merge(budget, event, left_on="link_to_event", right_on="event_id", how="inner")
filtered_df = merged_df[merged_df["category"] == "Advertisement"]
sorted_df = filtered_df.sort_values(by="spent", ascending=False)
result = sorted_df.iloc[0]["event_name"]


SELECT T3.cost FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'September Speaker' AND T3.expense_description = 'Posters'

merged_df1 = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
merged_df2 = pd.merge(merged_df1, expense, left_on="budget_id", right_on="link_to_budget", how="inner")
filtered_df = merged_df2[(merged_df2["event_name"] == "September Speaker") & (merged_df2["expense_description"] == "Posters")]
result = filtered_df["cost"].iloc[0]


SELECT T2.event_name FROM budget AS T1 INNER JOIN event AS T2 ON T2.event_id = T1.link_to_event WHERE T1.event_status = 'Closed' AND T1.remaining < 0 ORDER BY T1.remaining NULLS FIRST LIMIT 1

merged_df = pd.merge(budget, event, left_on="link_to_event", right_on="event_id", how="inner")
filtered_df = merged_df[(merged_df["event_status"] == "Closed") & (merged_df["remaining"] < 0)]
result = filtered_df.sort_values("remaining").iloc[0]["event_name"]


SELECT T1.type, SUM(T3.cost) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event INNER JOIN expense AS T3 ON T2.budget_id = T3.link_to_budget WHERE T1.event_name = 'October Meeting' GROUP BY T1.type

merged_df = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
merged_df = pd.merge(merged_df, expense, left_on="budget_id", right_on="link_to_budget", how="inner")
filtered_df = merged_df[merged_df["event_name"] == "October Meeting"]
result = filtered_df.groupby("type")["cost"].sum().reset_index()


SELECT T2.category, SUM(T2.amount) FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.event_name = 'April Speaker' GROUP BY T2.category ORDER BY SUM(T2.amount) ASC

merged_df = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
filtered_df = merged_df[merged_df["event_name"] == "April Speaker"]
grouped_df = filtered_df.groupby("category")["amount"].sum().reset_index()
result = grouped_df.sort_values(by="amount", ascending=True)


SELECT T2.expense_description FROM member AS T1 INNER JOIN expense AS T2 ON T1.member_id = T2.link_to_member WHERE T1.first_name = 'Sacha' AND T1.last_name = 'Harrison'

merged_df = pd.merge(member, expense, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df[(merged_df["first_name"] == "Sacha") & (merged_df["last_name"] == "Harrison")]
result = filtered_df["expense_description"]


SELECT DISTINCT T2.category FROM event AS T1 INNER JOIN budget AS T2 ON T1.event_id = T2.link_to_event WHERE T1.location = 'MU 215'

merged_df = pd.merge(event, budget, left_on="event_id", right_on="link_to_event", how="inner")
filtered_df = merged_df[merged_df["location"] == "MU 215"]
result = filtered_df["category"].unique()


SELECT CAST(SUM(CASE WHEN T2.amount = 50 THEN 1.0 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.income_id), 0) FROM member AS T1 INNER JOIN income AS T2 ON T1.member_id = T2.link_to_member WHERE T1.position = 'Member' AND T1.t_shirt_size = 'Medium'

merged_df = pd.merge(member, income, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df[(merged_df["position"] == "Member") & (merged_df["t_shirt_size"] == "Medium")]
count_amount_50 = (filtered_df["amount"] == 50).sum()
total_count = filtered_df["income_id"].count()
result = (count_amount_50 / total_count) * 100


SELECT DISTINCT event_name FROM event WHERE type = 'Game' AND DATE(SUBSTR(event_date, 1, 10)) BETWEEN '2019-03-15' AND '2020-03-20' AND status = 'Closed'

event['event_date'] = pd.to_datetime(event['event_date'].str[:10])
filtered_events = event[(event['type'] == 'Game') &
(event['event_date'] >= '2019-03-15') &
(event['event_date'] <= '2020-03-20') &
(event['status'] == 'Closed')]
result = filtered_events['event_name'].unique()


SELECT DISTINCT T3.first_name, T3.last_name, T3.phone FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member WHERE T1.cost > (SELECT AVG(T1.cost) FROM expense AS T1 INNER JOIN budget AS T2 ON T1.link_to_budget = T2.budget_id INNER JOIN member AS T3 ON T3.member_id = T1.link_to_member)

average_cost = expense["cost"].mean()
merged_df = pd.merge(expense, budget, left_on="link_to_budget", right_on="budget_id", how="inner")
merged_df = pd.merge(merged_df, member, left_on="link_to_member", right_on="member_id", how="inner")
filtered_df = merged_df[merged_df["cost"] > average_cost]
result = filtered_df[["first_name", "last_name", "phone"]].drop_duplicates()


SELECT DISTINCT T3.first_name, T3.last_name, T4.amount FROM event AS T1 INNER JOIN attendance AS T2 ON T1.event_id = T2.link_to_event INNER JOIN member AS T3 ON T3.member_id = T2.link_to_member INNER JOIN income AS T4 ON T4.link_to_member = T3.member_id WHERE T4.date_received = '2019-09-09'

merged_df1 = pd.merge(event, attendance, left_on="event_id", right_on="link_to_event", how="inner")
merged_df2 = pd.merge(merged_df1, member, left_on="link_to_member", right_on="member_id", how="inner")
merged_df3 = pd.merge(merged_df2, income, left_on="member_id", right_on="link_to_member", how="inner")
filtered_df = merged_df3[merged_df3["date_received"] == '2019-09-09']
result = filtered_df[["first_name", "last_name", "amount"]].drop_duplicates()


SELECT CAST(SUM(CASE WHEN Admission = '+' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE SEX = 'M'

male_patients = Patient[Patient["SEX"] == "M"]
in_patient_count = male_patients[male_patients["Admission"] == "+"].shape[0]
out_patient_count = male_patients[male_patients["Admission"] == "-"].shape[0]
result = (in_patient_count * 100.0) / out_patient_count


SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') > '1930' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(*), 0) FROM Patient WHERE SEX = 'F'

female_patients = Patient[Patient["SEX"] == "F"]
born_after_1930 = female_patients[female_patients["Birthday"].apply(lambda x: int(x[:4]) > 1930)]
percentage = (born_after_1930["ID"].count() / female_patients["ID"].count()) * 100
result = percentage


SELECT SUM(CASE WHEN Admission = '+' THEN 1.0 ELSE 0 END) / NULLIF(SUM(CASE WHEN Admission = '-' THEN 1 ELSE 0 END), 0) FROM Patient WHERE Diagnosis = 'SLE'

sle_patients = Patient[Patient["Diagnosis"] == "SLE"]
inpatient_count = sle_patients[sle_patients["Admission"] == "+"].shape[0]
outpatient_count = sle_patients[sle_patients["Admission"] == "-"].shape[0]
result = inpatient_count / outpatient_count


SELECT T1.Diagnosis, T2.Date FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID = 30609

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["ID"] == 30609]
result = filtered_df[["Diagnosis", "Date"]]


SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.LDH > 500

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df.loc[merged_df["LDH"] > 500].copy()
result = filtered_df[["ID", "SEX", "Birthday"]].drop_duplicates()


SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.RVVT = '+'

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Examination, on="ID", how="inner")
filtered_df = merged_df[merged_df["RVVT"] == "+"]
filtered_df["age"] = current_year - pd.to_datetime(filtered_df["Birthday"]).dt.year
result = filtered_df[["ID", "age"]].drop_duplicates()


SELECT DISTINCT T1.ID, T1.SEX, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T2.Thrombosis = 2

merged_df = pd.merge(Patient, Examination, on="ID", how="inner")
filtered_df = merged_df[merged_df["Thrombosis"] == 2]
result = filtered_df[["ID", "SEX", "Diagnosis_x"]].drop_duplicates()


SELECT COUNT(*) FROM Patient WHERE TO_CHAR(CAST(Description AS TIMESTAMP), 'YYYY') = '1997' AND SEX = 'F' AND Admission = '-'

Patient['Description'] = pd.to_datetime(Patient['Description'], errors='coerce')

filtered_df = Patient[(Patient["Description"].dt.year == 1997) & (Patient["SEX"] == "F") & (Patient["Admission"] == "-")]

result = len(filtered_df)


SELECT COUNT(*) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'F' AND TO_CHAR(CAST(T2."Examination Date" AS TIMESTAMP), 'YYYY') = '1997' AND T2.Thrombosis = 1

Examination['Examination Date'] = pd.to_datetime(Examination['Examination Date'])

merged_df = pd.merge(Patient, Examination, on="ID", how="inner")

filtered_df = merged_df[
(merged_df["SEX"] == "F") &
(merged_df["Examination Date"].dt.year == 1997) &
(merged_df["Thrombosis"] == 1)
]

result = len(filtered_df)


SELECT T2.Symptoms, T1.Diagnosis FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE NOT T2.Symptoms IS NULL ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Patient, Examination, on="ID", how="inner")
filtered_df = merged_df[merged_df["Symptoms"].notnull()]
sorted_df = filtered_df.sort_values(by="Birthday", ascending=False)
result = sorted_df[["Symptoms", "Diagnosis_x"]].head(1)


SELECT CAST(COUNT(DISTINCT CASE WHEN T2.UA <= 8.0 AND T1.SEX = 'M' THEN T1.ID ELSE NULL END) AS REAL) / NULLIF(COUNT(DISTINCT CASE WHEN T2.UA <= 6.5 AND T1.SEX = 'F' THEN T1.ID ELSE NULL END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
male_count = merged_df[(merged_df["UA"] <= 8.0) & (merged_df["SEX"] == 'M')]["ID"].nunique()
female_count = merged_df[(merged_df["UA"] <= 6.5) & (merged_df["SEX"] == 'F')]["ID"].nunique()
result = male_count / female_count


SELECT COUNT(T1.ID) FROM Patient AS T1 INNER JOIN Examination AS T2 ON T1.ID = T2.ID WHERE EXTRACT(YEAR FROM T2."Examination Date") BETWEEN 1990 AND 1993 AND EXTRACT(YEAR FROM T2."Examination Date") - EXTRACT(YEAR FROM T1.Birthday) < 18

merged_df = pd.merge(Patient, Examination, on="ID", how="inner")
merged_df["Examination Year"] = pd.to_datetime(merged_df["Examination Date"]).dt.year
merged_df["Birth Year"] = pd.to_datetime(merged_df["Birthday"]).dt.year
filtered_df = merged_df[(merged_df["Examination Year"] >= 1990) & (merged_df["Examination Year"] <= 1993) & ((merged_df["Examination Year"] - merged_df["Birth Year"]) < 18)]
result = filtered_df["ID"].nunique()


SELECT EXTRACT(YEAR FROM T2.Date) - EXTRACT(YEAR FROM T1.Birthday) AS age_difference, T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.HGB IS NOT NULL ORDER BY T2.HGB DESC LIMIT 1

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
merged_df['Age'] = pd.to_datetime(merged_df['Date']).dt.year - pd.to_datetime(merged_df['Birthday']).dt.year
highest_hgb_row = merged_df.loc[merged_df['HGB'].idxmax()]
result = (highest_hgb_row['Age'], highest_hgb_row['Diagnosis'])


SELECT "aCL IgM" FROM Examination WHERE ID IN (SELECT ID FROM Patient WHERE Diagnosis = 'SLE' AND Description = '1994-02-19') AND "Examination Date" = '1993-11-12'

patient_ids = Patient[(Patient["Diagnosis"] == "SLE") & (Patient["Description"] == "1994-02-19")]["ID"]
result = Examination[(Examination["ID"].isin(patient_ids)) & (Examination["Examination Date"] == "1993-11-12")]["aCL IgM"]


SELECT CAST((SUM(CASE WHEN T2.date::text LIKE '1981-11-%' THEN T2."T-CHO" ELSE 0 END) - SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2."T-CHO" ELSE 0 END)) AS REAL) / NULLIF(SUM(CASE WHEN T2.date::text LIKE '1981-12-%' THEN T2."T-CHO" ELSE 0 END), 0) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Birthday = '1959-02-18'

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["Birthday"] == "1959-02-18"]
november_sum = filtered_df[filtered_df["Date"].str.startswith("1981-11")]["T-CHO"].sum()
december_sum = filtered_df[filtered_df["Date"].str.startswith("1981-12")]["T-CHO"].sum()
result = (november_sum - december_sum) / december_sum


SELECT DISTINCT ID FROM Laboratory WHERE Date BETWEEN '1987-07-06' AND '1996-01-31' AND GPT > 30 AND ALB < 4

filtered_df = Laboratory[(Laboratory["Date"] >= '1987-07-06') & (Laboratory["Date"] <= '1996-01-31') & (Laboratory["GPT"] > 30) & (Laboratory["ALB"] < 4)]
result = filtered_df["ID"].unique()


SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.Admission = '-' AND T2."T-BIL" < 2.0 AND T2.Date::text LIKE '1991-10-%'

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["Admission"] == "-") & (merged_df["T-BIL"] < 2.0) & (merged_df["Date"].str.startswith("1991-10"))]
result = filtered_df["ID"].unique()


SELECT AVG(T2.ALB) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT > 400 AND T1.Diagnosis = 'SLE' AND T1.SEX = 'F'

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[(merged_df["PLT"] > 400) & (merged_df["Diagnosis"] == "SLE") & (merged_df["SEX"] == "F")]
result = filtered_df["ALB"].mean()


SELECT CAST(SUM(CASE WHEN SEX = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(ID), 0) FROM Patient WHERE Diagnosis = 'RA' AND TO_CHAR(CAST(Birthday AS TIMESTAMP), 'YYYY') = '1980'

Patient['Birthday'] = pd.to_datetime(Patient['Birthday'], errors='coerce')
filtered_df = Patient[(Patient["Diagnosis"] == "RA") & (Patient["Birthday"].dt.year == 1980)]
female_count = (filtered_df["SEX"] == "F").sum()
total_count = filtered_df["ID"].count()
result = (female_count / total_count) * 100


SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.SEX = 'M' AND T2.GPT >= 60

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["SEX"] == "M") & (merged_df["GPT"] >= 60)]
result = filtered_df["ID"].unique()


SELECT DISTINCT ON (T1.Birthday) T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GPT > 60 ORDER BY T1.Birthday ASC

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["GPT"] > 60]
sorted_df = filtered_df.sort_values(by="Birthday", ascending=True)
result = sorted_df["Diagnosis"].drop_duplicates().reset_index(drop=True)


SELECT DISTINCT T1.ID, T1.SEX, T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.UN = 29

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")

filtered_df = merged_df[merged_df["UN"] == 29]

result = filtered_df[["ID", "SEX", "Birthday"]].drop_duplicates()


SELECT AVG(T3.age) FROM (SELECT DISTINCT T1.ID,EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM T1.Birthday) AS age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2."T-CHO" >= 250 AND T1.SEX = 'M') AS T3

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["T-CHO"] >= 250) & (merged_df["SEX"] == 'M')]
filtered_df["age"] = current_year - pd.to_datetime(filtered_df["Birthday"]).dt.year
distinct_ages = filtered_df.drop_duplicates(subset=["ID"])["age"]
result = distinct_ages.mean()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.TG >= 200 AND EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) > 50

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[(merged_df["TG"] >= 200) & ((current_year - pd.to_datetime(merged_df["Birthday"]).dt.year) > 50)]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE TO_CHAR(CAST(T1.Birthday AS TIMESTAMP), 'YYYY') BETWEEN '1936' AND '1956' AND T1.SEX = 'M' AND T2.CPK >= 250

Patient['Birthday'] = pd.to_datetime(Patient['Birthday'], errors='coerce')

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")

filtered_df = merged_df[
(merged_df["Birthday"].dt.year.between(1936, 1956)) &
(merged_df["SEX"] == "M") &
(merged_df["CPK"] >= 250)
]

result = filtered_df["ID"].nunique()


SELECT DISTINCT T1.ID, T1.SEX, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GLU >= 180 AND T2."T-CHO" < 250

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["GLU"] >= 180) & (merged_df["T-CHO"] < 250)]
filtered_df["Age"] = current_year - pd.to_datetime(filtered_df["Birthday"]).dt.year
result = filtered_df[["ID", "SEX", "Age"]].drop_duplicates()


SELECT DISTINCT T1.Diagnosis, T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.RBC < 3.5

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["RBC"] < 3.5]
filtered_df["Age"] = current_year - pd.to_datetime(filtered_df["Birthday"]).dt.year
result = filtered_df[["Diagnosis", "ID", "Age"]].drop_duplicates()


SELECT DISTINCT T1.ID, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) AS Age FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T1.ID IN (SELECT ID FROM Laboratory WHERE HCT >= 52 GROUP BY ID HAVING COUNT(ID) >= 2)

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_lab = Laboratory[Laboratory["HCT"] >= 52].groupby("ID").filter(lambda x: len(x) >= 2)
filtered_df = merged_df[merged_df["ID"].isin(filtered_lab["ID"])]
result = filtered_df[["ID", "Birthday"]].drop_duplicates()
result["Age"] = current_year - pd.to_datetime(result["Birthday"]).dt.year
result = result[["ID", "Age"]]


SELECT DISTINCT T1.ID FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.PLT BETWEEN 100 AND 400 AND EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T1.Birthday) < 50 AND EXTRACT(YEAR FROM T2.Date) = 1984

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[
(merged_df["PLT"] >= 100) &
(merged_df["PLT"] <= 400) &
(current_year - pd.to_datetime(merged_df["Birthday"]).dt.year < 50) &
(pd.to_datetime(merged_df["Date"]).dt.year == 1984)
]
result = filtered_df["ID"].unique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE (T2.FG <= 150 OR T2.FG >= 450) AND T2.WBC > 3.5 AND T2.WBC < 9.0 AND T1.SEX = 'M'

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["SEX"] == "M") & (merged_df["WBC"] > 3.5) & (merged_df["WBC"] < 9.0) & ((merged_df["FG"] <= 150) | (merged_df["FG"] >= 450))]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.IGG >= 2000

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["IGG"] >= 2000]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE T2.IGG BETWEEN 900 AND 2000 AND NOT T3.Symptoms IS NULL

merged_df_1 = pd.merge(Patient, Laboratory, on="ID", how="inner")
merged_df_2 = pd.merge(merged_df_1, Examination, on="ID", how="inner")
filtered_df = merged_df_2[(merged_df_2["IGG"] > 900) & (merged_df_2["IGG"] < 2000) & (merged_df_2["Symptoms"].notnull())]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.IGA BETWEEN 80 AND 500 AND TO_CHAR(CAST(T1."First Date" AS TIMESTAMP), 'YYYY') >= '1990'

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["IGA"] > 80) & (merged_df["IGA"] < 500) & (pd.to_datetime(merged_df["First Date"]).dt.year >= 1990)]
result = filtered_df["ID"].nunique()


SELECT T3.Diagnosis FROM (SELECT DISTINCT T1.ID, T1.Diagnosis FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.IGM <= 40 OR T2.IGM >= 400) AS T3 GROUP BY Diagnosis ORDER BY COUNT(*) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Patient, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["IGM"] <= 40) | (merged_df["IGM"] >= 400)]
distinct_df = filtered_df[["ID", "Diagnosis"]].drop_duplicates()
result = distinct_df["Diagnosis"].value_counts().idxmax()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.CRE >= 1.5 AND EXTRACT(YEAR FROM AGE(CURRENT_DATE, T1.Birthday)) < 70

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[(merged_df["CRE"] >= 1.5) & ((current_year - pd.to_datetime(merged_df["Birthday"]).dt.year) < 70)]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Examination AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.SM IN ('negative', '0') AND T1.Thrombosis = 0

merged_df = pd.merge(Examination, Laboratory, on="ID", how="inner")
filtered_df = merged_df[(merged_df["SM"].isin(['negative', '0'])) & (merged_df["Thrombosis"] == 0)]
result = filtered_df["ID"].nunique()


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T3.ID = T2.ID WHERE (T2.SC170 = 'negative' OR T2.SC170 = '0') AND T1.SEX = 'F' AND T3.Symptoms IS NULL

merged_df_1 = pd.merge(Patient, Laboratory, on="ID", how="inner")
merged_df_2 = pd.merge(merged_df_1, Examination, on="ID", how="inner")
filtered_df = merged_df_2[((merged_df_2["SC170"] == "negative") | (merged_df_2["SC170"] == "0")) & (merged_df_2["SEX"] == "F") & (merged_df_2["Symptoms"].isnull())]
result = filtered_df["ID"].nunique()


SELECT T1.Birthday FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID WHERE T2.GOT >= 60 ORDER BY T1.Birthday DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Patient, Laboratory, left_on="ID", right_on="ID", how="inner")
filtered_df = merged_df[merged_df["GOT"] >= 60]
result = filtered_df.sort_values(by="Birthday", ascending=False).iloc[0]["Birthday"]


SELECT COUNT(DISTINCT T1.ID) FROM Patient AS T1 INNER JOIN Laboratory AS T2 ON T1.ID = T2.ID INNER JOIN Examination AS T3 ON T1.ID = T3.ID WHERE T2.CPK < 250 AND (T3.KCT = '+' OR T3.RVVT = '+' OR T3.LAC = '+')

merged_df_1 = pd.merge(Patient, Laboratory, on="ID", how="inner")
merged_df_2 = pd.merge(merged_df_1, Examination, on="ID", how="inner")
filtered_df = merged_df_2[(merged_df_2["CPK"] < 250) & ((merged_df_2["KCT"] == '+') | (merged_df_2["RVVT"] == '+') | (merged_df_2["LAC"] == '+'))]
result = filtered_df["ID"].nunique()


SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' GROUP BY t2.name ORDER BY SUM(t1.home_team_goal + t1.away_team_goal) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Match, League, left_on="league_id", right_on="id", how="inner")

filtered_df = merged_df[merged_df["season"] == "2015/2016"]

grouped_df = (
filtered_df.groupby("name")
.agg(
total_home_goals=("home_team_goal", "sum"),
total_away_goals=("away_team_goal", "sum")
)
)

grouped_df["total_goals"] = grouped_df["total_home_goals"] + grouped_df["total_away_goals"]

result = grouped_df["total_goals"].idxmax()


SELECT t1.buildUpPlaySpeed FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id ORDER BY t1.buildUpPlaySpeed DESC NULLS LAST LIMIT 4

merged_df = pd.merge(Team_Attributes, Team, left_on="team_api_id", right_on="team_api_id", how="inner")
sorted_df = merged_df.sort_values(by="buildUpPlaySpeed", ascending=False)
result = sorted_df["buildUpPlaySpeed"].head(4)


SELECT t2.name FROM Match AS t1 INNER JOIN League AS t2 ON t1.league_id = t2.id WHERE t1.season = '2015/2016' AND t1.home_team_goal = t1.away_team_goal GROUP BY t2.name ORDER BY COUNT(t1.id) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Match, League, left_on="league_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["season"] == "2015/2016") & (merged_df["home_team_goal"] == merged_df["away_team_goal"])]
draw_counts = filtered_df.groupby("name").size()
result = draw_counts.idxmax()


SELECT DISTINCT EXTRACT(YEAR FROM AGE(NOW(), t2.birthday::timestamp)) + (CASE WHEN EXTRACT(MONTH FROM AGE(NOW(), t2.birthday::timestamp)) > 0 OR EXTRACT(DAY FROM AGE(NOW(), t2.birthday::timestamp)) > 0 THEN 1 ELSE 0 END) AS age FROM Player_Attributes AS t1 INNER JOIN Player AS t2 ON t1.player_api_id = t2.player_api_id WHERE EXTRACT(YEAR FROM t1.date::date) BETWEEN 2013 AND 2015 AND t1.sprint_speed >= 97

from datetime import datetime
merged_df = pd.merge(Player_Attributes, Player, on="player_api_id", how="inner")

merged_df["date"] = pd.to_datetime(merged_df["date"], errors="coerce")

filtered_df = merged_df[
(merged_df["sprint_speed"] >= 97) &
(merged_df["date"].dt.year >= 2013) &
(merged_df["date"].dt.year <= 2015)
]

filtered_df["birthday"] = pd.to_datetime(filtered_df["birthday"], errors="coerce")

filtered_df["age"] = datetime.now().year - filtered_df["birthday"].dt.year
filtered_df["age"] += (
(datetime.now().month > filtered_df["birthday"].dt.month) |
((datetime.now().month == filtered_df["birthday"].dt.month) &
(datetime.now().day >= filtered_df["birthday"].dt.day))
).astype(int)

result = filtered_df["age"].unique()


SELECT t2.name, t1.max_count FROM League AS t2 JOIN (SELECT league_id, MAX(cnt) AS max_count FROM (SELECT league_id, COUNT(id) AS cnt FROM Match GROUP BY league_id) AS subquery GROUP BY league_id ORDER BY MAX(cnt) DESC LIMIT 1) AS t1 ON t1.league_id = t2.id

match_counts = Match.groupby('league_id').size().reset_index(name='cnt')
max_count = match_counts['cnt'].max()
max_league_id = match_counts[match_counts['cnt'] == max_count]['league_id'].iloc[0]
league_name = League[League['id'] == max_league_id]['name'].iloc[0]
result = (league_name, max_count)


SELECT DISTINCT team_fifa_api_id FROM Team_Attributes WHERE buildUpPlaySpeed > 50 AND buildUpPlaySpeed < 60

filtered_df = Team_Attributes[(Team_Attributes["buildUpPlaySpeed"] > 50) & (Team_Attributes["buildUpPlaySpeed"] < 60)]
result = filtered_df["team_fifa_api_id"].unique()


SELECT CAST(COUNT(DISTINCT CASE WHEN t2.preferred_foot = 'left' THEN t1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT t1.id), 0) AS percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t1.birthday, 1, 4) BETWEEN '1987' AND '1992'

merged_df = pd.merge(Player, Player_Attributes, left_on="player_api_id", right_on="player_api_id", how="inner")
filtered_df = merged_df[(merged_df["birthday"].str[:4].astype(int) >= 1987) & (merged_df["birthday"].str[:4].astype(int) <= 1992)]
left_foot_count = filtered_df[filtered_df["preferred_foot"] == "left"]["id_x"].nunique()
total_count = filtered_df["id_x"].nunique()
result = (left_foot_count / total_count) * 100


SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 180 GROUP BY t1.id ORDER BY CAST(SUM(t2.heading_accuracy) AS REAL) / NULLIF(COUNT(t2."player_fifa_api_id"), 0) DESC NULLS LAST LIMIT 10

merged_df = pd.merge(Player, Player_Attributes, on="player_api_id", how="inner")

filtered_df = merged_df[merged_df["height"] > 180]

grouped_df = filtered_df.groupby("player_api_id").agg(
player_name=("player_name", "first"),
avg_heading_accuracy=("heading_accuracy", "mean")
)

sorted_df = grouped_df.sort_values(by="avg_heading_accuracy", ascending=False)

result = sorted_df.head(10)["player_name"].tolist()


SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2009/2010' GROUP BY t1.name HAVING (CAST(SUM(t2.home_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) - (CAST(SUM(t2.away_team_goal) AS REAL) / NULLIF(COUNT(DISTINCT t2.id), 0)) > 0

merged_df = pd.merge(League, Match, left_on="id", right_on="league_id", how="inner")

filtered_df = merged_df[merged_df["season"] == "2009/2010"]

grouped_df = (
filtered_df.groupby("name")
.agg(
total_home_goals=("home_team_goal", "sum"),
total_away_goals=("away_team_goal", "sum"),
distinct_matches=("id_y", "nunique")
)
)

grouped_df["home_goals_avg"] = grouped_df["total_home_goals"] / grouped_df["distinct_matches"]
grouped_df["away_goals_avg"] = grouped_df["total_away_goals"] / grouped_df["distinct_matches"]

result = grouped_df[grouped_df["home_goals_avg"] > grouped_df["away_goals_avg"]].index.tolist()


SELECT player_name FROM Player WHERE SUBSTR(birthday, 1, 7) = '1970-10'


SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.player_name = 'Gabriel Tamas' AND TO_CHAR(CAST(t2.date AS TIMESTAMP), 'YYYY') = '2011'

merged_df = pd.merge(Player, Player_Attributes, on="player_api_id", how="inner")
filtered_df = merged_df[(merged_df["player_name"] == "Gabriel Tamas") & (merged_df["date"].str[:4] == "2011")]
result = filtered_df["overall_rating"]


SELECT A FROM (SELECT AVG(finishing) AS result, 'highest' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MAX(height) FROM Player) UNION SELECT AVG(finishing) AS result, 'Min' AS A FROM Player AS T1 INNER JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T1.height = (SELECT MIN(height) FROM Player)) AS subquery ORDER BY result DESC LIMIT 1

max_height = Player["height"].max()
min_height = Player["height"].min()

highest_df = Player[Player["height"] == max_height]
shortest_df = Player[Player["height"] == min_height]

highest_merged = pd.merge(highest_df, Player_Attributes, on="player_api_id", how="inner")
shortest_merged = pd.merge(shortest_df, Player_Attributes, on="player_api_id", how="inner")

highest_avg_finishing = highest_merged["finishing"].mean()
shortest_avg_finishing = shortest_merged["finishing"].mean()

result = "highest" if highest_avg_finishing > shortest_avg_finishing else "Min"


SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 170 AND TO_CHAR(CAST(t2."date" AS TIMESTAMP), 'YYYY') >= '2010' AND TO_CHAR(CAST(t2."date" AS TIMESTAMP), 'YYYY') <= '2015'

merged_df = pd.merge(Player, Player_Attributes, left_on="player_api_id", right_on="player_api_id", how="inner")
filtered_df = merged_df[(merged_df["height"] > 170) & (merged_df["date"].str[:4] >= '2010') & (merged_df["date"].str[:4] <= '2015')]
result = filtered_df["overall_rating"].sum() / filtered_df["id_y"].nunique()


SELECT t1.name FROM League AS t1 JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2008/2009' GROUP BY t1.name HAVING COUNT(t2.id) = (SELECT MAX(match_count) FROM (SELECT COUNT(t2.id) AS match_count FROM Match AS t2 WHERE t2.season = '2008/2009' GROUP BY t2.league_id) AS subquery)

merged_df = pd.merge(League, Match, left_on="id", right_on="league_id", how="inner")

season_df = merged_df[merged_df["season"] == "2008/2009"]

league_match_counts = season_df.groupby("name")["id_y"].count()

max_matches = league_match_counts.max()

result = league_match_counts[league_match_counts == max_matches].index.tolist()


SELECT (SUM(CASE WHEN t1.player_name = 'Ariel Borysiuk' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Paulin Puel' THEN t2.overall_rating ELSE 0 END), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id

merged_df = pd.merge(Player, Player_Attributes, on="player_api_id", how="inner")
ariel_rating = merged_df.loc[merged_df["player_name"] == "Ariel Borysiuk", "overall_rating"].sum()
paulin_rating = merged_df.loc[merged_df["player_name"] == "Paulin Puel", "overall_rating"].sum()
result = ((ariel_rating - paulin_rating) * 100) / paulin_rating


SELECT t2.chanceCreationPassing, t2.chanceCreationPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Ajax' ORDER BY t2.chanceCreationPassing DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Team, Team_Attributes, on="team_api_id", how="inner")

filtered_df = merged_df[merged_df["team_long_name"] == "Ajax"]

sorted_df = filtered_df.sort_values(by="chanceCreationPassing", ascending=False)

result = sorted_df[["chanceCreationPassing", "chanceCreationPassingClass"]].head(1)


SELECT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2."date", 1, 10) = '2016-06-23' AND t2.overall_rating = 77 ORDER BY t1.birthday ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(Player, Player_Attributes, on="player_api_id", how="inner")
filtered_df = merged_df[(merged_df["date"].str.startswith("2016-06-23")) & (merged_df["overall_rating"] == 77)]
oldest_player = filtered_df.sort_values("birthday").iloc[0]
result = oldest_player["player_name"]


SELECT t2.overall_rating FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE SUBSTR(t2."date", 1, 10) = '2016-02-04' AND t1.player_name = 'Aaron Mooy'

merged_df = pd.merge(Player, Player_Attributes, on="player_api_id", how="inner")
filtered_df = merged_df[(merged_df["date"].str.startswith("2016-02-04")) & (merged_df["player_name"] == "Aaron Mooy")]
result = filtered_df["overall_rating"].iloc[0]


SELECT t2.buildUpPlayPassingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'FC Lorient' AND t2."date" LIKE '2010-02-22%'

merged_df = pd.merge(Team, Team_Attributes, on="team_api_id", how="inner")
filtered_df = merged_df[(merged_df["team_long_name"] == "FC Lorient") & (merged_df["date"].str.startswith("2010-02-22"))]
result = filtered_df["buildUpPlayPassingClass"].iloc[0]


SELECT t2.defenceAggressionClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_long_name = 'Hannover 96' AND t2."date" LIKE '2015-09-10%'

merged_df = pd.merge(Team, Team_Attributes, on="team_api_id", how="inner")
filtered_df = merged_df[(merged_df["team_long_name"] == "Hannover 96") & (merged_df["date"].str.startswith("2015-09-10"))]
result = filtered_df["defenceAggressionClass"].iloc[0]


SELECT CAST(SUM(t2.overall_rating) AS REAL) / NULLIF(COUNT(t2.id), 0) FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE t1.player_name = 'Marko Arnautovic' AND SUBSTR(t2."date", 1, 10) BETWEEN '2007-02-22' AND '2016-04-21'

merged_df = pd.merge(Player, Player_Attributes, left_on="player_fifa_api_id", right_on="player_fifa_api_id", how="inner")
filtered_df = merged_df[(merged_df["player_name"] == "Marko Arnautovic") & (merged_df["date"].str[:10] >= "2007-02-22") & (merged_df["date"].str[:10] <= "2016-04-21")]
result = filtered_df["overall_rating"].mean()


SELECT (SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END) * 1.0 - SUM(CASE WHEN t1.player_name = 'Jordan Bowery' THEN t2.overall_rating ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN t1.player_name = 'Landon Donovan' THEN t2.overall_rating ELSE 0 END), 0) AS LvsJ_percent FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_fifa_api_id = t2.player_fifa_api_id WHERE SUBSTR(t2."date", 1, 10) = '2013-07-12'

merged_df = pd.merge(Player, Player_Attributes, on="player_fifa_api_id", how="inner")
filtered_df = merged_df[merged_df["date"].str[:10] == '2013-07-12']
landon_rating = filtered_df.loc[filtered_df["player_name"] == 'Landon Donovan', "overall_rating"].sum()
jordan_rating = filtered_df.loc[filtered_df["player_name"] == 'Jordan Bowery', "overall_rating"].sum()
result = ((landon_rating - jordan_rating) * 100) / landon_rating


SELECT player_name FROM (SELECT player_name, height, DENSE_RANK() OVER (ORDER BY height DESC) AS rank FROM Player) AS subquery WHERE rank = 1

Player['rank'] = Player['height'].rank(method='dense', ascending=False)
result = Player[Player['rank'] == 1]['player_name'].tolist()


SELECT DISTINCT t1.player_name FROM Player AS t1 INNER JOIN Player_Attributes AS t2 ON t1.player_api_id = t2.player_api_id WHERE t2.attacking_work_rate = 'high'

merged_df = pd.merge(Player, Player_Attributes, left_on="player_api_id", right_on="player_api_id", how="inner")
filtered_df = merged_df[merged_df["attacking_work_rate"] == "high"]
result = filtered_df["player_name"].unique()


SELECT DISTINCT t1.team_short_name FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.chanceCreationPassingClass = 'Safe'

merged_df = pd.merge(Team, Team_Attributes, left_on="team_api_id", right_on="team_api_id", how="inner")
filtered_df = merged_df[merged_df["chanceCreationPassingClass"] == "Safe"]
result = filtered_df["team_short_name"].unique()


SELECT SUM(CASE WHEN t1.id = 6 THEN t1.jumping ELSE 0 END) - SUM(CASE WHEN t1.id = 23 THEN t1.jumping ELSE 0 END) FROM Player_Attributes AS t1

jumping_6 = Player_Attributes.loc[Player_Attributes["id"] == 6, "jumping"].sum()
jumping_23 = Player_Attributes.loc[Player_Attributes["id"] == 23, "jumping"].sum()
result = jumping_6 - jumping_23


SELECT id FROM Player_Attributes WHERE preferred_foot = 'right' ORDER BY potential ASC NULLS LAST LIMIT 4

filtered_df = Player_Attributes[Player_Attributes["preferred_foot"] == "right"]
sorted_df = filtered_df.sort_values(by="potential", ascending=True)
result = sorted_df["id"].head(4).tolist()


SELECT COUNT(DISTINCT t1.player_api_id) FROM Player_Attributes AS t1 WHERE t1.preferred_foot = 'left' AND t1.crossing = (SELECT MAX(crossing) FROM Player_Attributes)

max_crossing = Player_Attributes["crossing"].max()
filtered_df = Player_Attributes[(Player_Attributes["preferred_foot"] == "left") & (Player_Attributes["crossing"] == max_crossing)]
result = filtered_df["player_api_id"].nunique()


SELECT DISTINCT t1.buildUpPlaySpeedClass FROM Team_Attributes AS t1 INNER JOIN Team AS t2 ON t1.team_api_id = t2.team_api_id WHERE t2.team_long_name = 'KSV Cercle Brugge'

merged_df = pd.merge(Team_Attributes, Team, left_on="team_api_id", right_on="team_api_id", how="inner")
filtered_df = merged_df[merged_df["team_long_name"] == "KSV Cercle Brugge"]
result = filtered_df["buildUpPlaySpeedClass"].unique()


SELECT id, finishing, curve FROM Player_Attributes WHERE player_api_id = (SELECT player_api_id FROM Player ORDER BY weight DESC NULLS LAST LIMIT 1) LIMIT 1

heaviest_player_id = Player.loc[Player['weight'].idxmax(), 'player_api_id']
result = Player_Attributes[Player_Attributes['player_api_id'] == heaviest_player_id][['id', 'finishing', 'curve']].head(1)


SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2015/2016' GROUP BY t1.name ORDER BY COUNT(t2.id) DESC NULLS LAST LIMIT 4

merged_df = pd.merge(League, Match, left_on="id", right_on="league_id", how="inner")
filtered_df = merged_df[merged_df["season"] == "2015/2016"]
grouped_df = filtered_df.groupby("name").size().reset_index(name="game_count")
sorted_df = grouped_df.sort_values(by="game_count", ascending=False)
result = sorted_df.head(4)["name"].tolist()


SELECT t2.team_long_name FROM Match AS t1 INNER JOIN Team AS t2 ON t1.away_team_api_id = t2.team_api_id ORDER BY t1.away_team_goal DESC NULLS LAST LIMIT 1

merged_df = pd.merge(Match, Team, left_on="away_team_api_id", right_on="team_api_id", how="inner")
result = merged_df.loc[merged_df["away_team_goal"].idxmax(), "team_long_name"]


SELECT T2.driverRef FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 20 ORDER BY T1.q1 DESC NULLS LAST LIMIT 5

merged_df = pd.merge(qualifying, drivers, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[merged_df["raceId"] == 20]
sorted_df = filtered_df.sort_values(by="q1", ascending=False)
result = sorted_df.head(5)["driverRef"].tolist()


SELECT T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 19 ORDER BY T1.q2 ASC LIMIT 1

merged_df = pd.merge(qualifying, drivers, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[merged_df["raceId"] == 19]
sorted_df = filtered_df.sort_values(by="q2", ascending=True, na_position='last')
result = sorted_df.iloc[0]["surname"]


SELECT DISTINCT T2.name FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T1.country = 'Germany'

merged_df = pd.merge(circuits, races, left_on="circuitId", right_on="circuitId", how="inner")
filtered_df = merged_df[merged_df["country"] == "Germany"]
result = filtered_df["name_y"].unique()


SELECT DISTINCT T1.lat, T1.lng FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'Australian Grand Prix'

merged_df = pd.merge(circuits, races, left_on="circuitId", right_on="circuitId", how="inner")
filtered_df = merged_df[merged_df["name_y"] == "Australian Grand Prix"]
result = filtered_df[["lat", "lng"]].drop_duplicates()


SELECT T1.forename, T1.surname FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T2.raceId = 592 AND NOT T2.time IS NULL AND NOT T1.dob IS NULL ORDER BY T1.dob ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(drivers, results, on="driverId", how="inner")
filtered_df = merged_df[(merged_df["raceId"] == 592) & (merged_df["time"].notna()) & (merged_df["dob"].notna())]
oldest_driver = filtered_df.sort_values("dob").iloc[0]
result = (oldest_driver["forename"], oldest_driver["surname"])


SELECT DISTINCT T2.forename, T2.surname, T2.url FROM lapTimes AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 161 AND T1.time LIKE '1:27%'

merged_df = pd.merge(lapTimes, drivers, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[(merged_df["raceId"] == 161) & (merged_df["time"].str.startswith('1:27'))]
result = filtered_df[["forename", "surname", "url"]].drop_duplicates()


SELECT T2.url FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T2.constructorId = T1.constructorId WHERE T1.raceId = 9 ORDER BY T1.points DESC NULLS LAST LIMIT 1

merged_df = pd.merge(constructorResults, constructors, left_on="constructorId", right_on="constructorId", how="inner")
filtered_df = merged_df[merged_df["raceId"] == 9]
sorted_df = filtered_df.sort_values(by="points", ascending=False)
result = sorted_df.iloc[0]["url"]


SELECT T2.code FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T2.driverId = T1.driverId WHERE T1.raceId = 45 AND T1.q3 LIKE '1:33%'

merged_df = pd.merge(qualifying, drivers, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[(merged_df["raceId"] == 45) & (merged_df["q3"].str.startswith("1:33"))]
result = filtered_df["code"].iloc[0]


SELECT T1.nationality FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId ORDER BY CAST(T2.fastestLapSpeed AS REAL) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(drivers, results, left_on="driverId", right_on="driverId", how="inner")
merged_df["fastestLapSpeed"] = pd.to_numeric(merged_df["fastestLapSpeed"], errors='coerce')
max_speed_driver = merged_df.loc[merged_df["fastestLapSpeed"].idxmax()]
result = max_speed_driver["nationality"]


SELECT (SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END) - SUM(CASE WHEN T2.raceId = 854 THEN T2.fastestLapSpeed::numeric ELSE 0 END)) * 100 / NULLIF(SUM(CASE WHEN T2.raceId = 853 THEN T2.fastestLapSpeed::numeric ELSE 0 END), 0) FROM drivers AS T1 INNER JOIN results AS T2 ON T2.driverId = T1.driverId WHERE T1.forename = 'Paul' AND T1.surname = 'di Resta'

merged_df = pd.merge(drivers, results, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[(merged_df["forename"] == "Paul") & (merged_df["surname"] == "di Resta")]

filtered_df["fastestLapSpeed"] = pd.to_numeric(filtered_df["fastestLapSpeed"], errors='coerce')

race_853_speed = filtered_df[filtered_df["raceId"] == 853]["fastestLapSpeed"].sum()
race_854_speed = filtered_df[filtered_df["raceId"] == 854]["fastestLapSpeed"].sum()

result = ((race_853_speed - race_854_speed) * 100) / race_853_speed


SELECT CAST(COUNT(CASE WHEN NOT T2.time IS NULL THEN T2.driverId END) AS REAL) * 100 / NULLIF(COUNT(T2.driverId), 0) FROM races AS T1 INNER JOIN results AS T2 ON T2.raceId = T1.raceId WHERE T1.date = '1983-07-16'

merged_df = pd.merge(races, results, left_on="raceId", right_on="raceId", how="inner")
filtered_df = merged_df[merged_df["date"] == '1983-07-16']
completion_count = filtered_df["time_y"].notnull().sum()
total_count = filtered_df["driverId"].count()
result = (completion_count / total_count) * 100


SELECT T2.milliseconds, T1.forename, T1.surname, T3.name FROM drivers AS T1 INNER JOIN lapTimes AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T2.raceId = T3.raceId ORDER BY T2.milliseconds ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(drivers, lapTimes, on="driverId", how="inner")

merged_df = pd.merge(merged_df, races, on="raceId", how="inner")

sorted_df = merged_df.sort_values(by="milliseconds", ascending=True)

best_lap = sorted_df.iloc[0][["milliseconds", "forename", "surname", "name"]]

result = best_lap.to_frame().T


SELECT T1.forename, T1.surname, T1.nationality, MAX(T2.points) FROM drivers AS T1 INNER JOIN driverStandings AS T2 ON T2.driverId = T1.driverId WHERE T2.wins >= 1 GROUP BY T1.forename, T1.surname, T1.nationality ORDER BY COUNT(T2.wins) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(drivers, driverStandings, left_on="driverId", right_on="driverId", how="inner")
filtered_df = merged_df[merged_df["wins"] >= 1]
grouped_df = filtered_df.groupby(["forename", "surname", "nationality"]).agg({"wins": "count", "points": "max"})
sorted_df = grouped_df.sort_values(by="wins", ascending=False).head(1)
result = sorted_df.reset_index()[["forename", "surname", "nationality", "points"]]


SELECT DISTINCT T2.name, T1.name, T1.location FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.year = 2005 AND TO_CHAR(CAST(T2.date AS TIMESTAMP), 'MM') = '09'

merged_df = pd.merge(circuits, races, left_on="circuitId", right_on="circuitId", how="inner")
filtered_df = merged_df[(merged_df["year"] == 2005) & (pd.to_datetime(merged_df["date"]).dt.month == 9)]
result = filtered_df[["name_y", "name_x", "location"]].drop_duplicates()


SELECT CAST(COUNT(CASE WHEN T1.country = 'Germany' THEN T2.circuitID END) AS REAL) * 100 / NULLIF(COUNT(T2.circuitId), 0) FROM circuits AS T1 INNER JOIN races AS T2 ON T2.circuitID = T1.circuitId WHERE T2.name = 'European Grand Prix'

merged_df = pd.merge(circuits, races, left_on="circuitId", right_on="circuitId", how="inner")
european_gp_df = merged_df[merged_df["name_y"] == "European Grand Prix"]
germany_count = european_gp_df[european_gp_df["country"] == "Germany"].shape[0]
total_count = european_gp_df.shape[0]
result = (germany_count / total_count) * 100


SELECT T2.name FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T1.raceId = 291

merged_df = pd.merge(constructorStandings, constructors, left_on="constructorId", right_on="constructorId", how="inner")
filtered_df = merged_df[(merged_df["points"] == 0) & (merged_df["raceId"] == 291)]
result = filtered_df["name"].tolist()


SELECT COUNT(DISTINCT T1.constructorId) FROM constructorStandings AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId WHERE T1.points = 0 AND T2.nationality = 'Japanese' GROUP BY T1.constructorId HAVING COUNT(raceId) = 2

merged_df = pd.merge(constructorStandings, constructors, on="constructorId", how="inner")
filtered_df = merged_df[(merged_df["points"] == 0) & (merged_df["nationality"] == "Japanese")]
grouped_df = filtered_df.groupby("constructorId").filter(lambda x: x["raceId"].nunique() == 2)
result = grouped_df["constructorId"].nunique()


SELECT AVG(CAST(T1.fastestLapSpeed AS NUMERIC)) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId WHERE T2.year = 2009 AND T2.name = 'Spanish Grand Prix'

merged_df = pd.merge(results, races, left_on="raceId", right_on="raceId", how="inner")
filtered_df = merged_df[(merged_df["year"] == 2009) & (merged_df["name"] == "Spanish Grand Prix")]
filtered_df["fastestLapSpeed"] = pd.to_numeric(filtered_df["fastestLapSpeed"], errors='coerce')
result = filtered_df["fastestLapSpeed"].mean()


SELECT COUNT(*) FROM (SELECT nationality FROM drivers ORDER BY dob DESC LIMIT 3) AS T3 WHERE nationality = 'Dutch'

sorted_drivers = drivers.sort_values(by="dob", ascending=False)
youngest_drivers = sorted_drivers.head(3)
result = youngest_drivers[youngest_drivers["nationality"] == "Dutch"].shape[0]


SELECT T2.forename, T2.surname FROM pitStops AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId WHERE T2.nationality = 'German' AND EXTRACT(YEAR FROM T2.dob) BETWEEN 1980 AND 1985 GROUP BY T2.forename, T2.surname ORDER BY AVG(CAST(T1.duration AS INTERVAL))  LIMIT 3

filtered_drivers = drivers[(drivers["nationality"] == "German") & (drivers["dob"].between("1980-01-01", "1985-12-31"))]
merged_df = pd.merge(pitStops, filtered_drivers, on="driverId", how="inner")
merged_df["duration"] = pd.to_numeric(merged_df["duration"], errors="coerce")
avg_duration = merged_df.groupby(["forename", "surname"])["duration"].mean().reset_index()
sorted_drivers = avg_duration.sort_values(by="duration").head(3)
result = sorted_drivers[["forename", "surname"]]


SELECT SUM(T1.points), T2.name, T2.nationality FROM constructorResults AS T1 INNER JOIN constructors AS T2 ON T1.constructorId = T2.constructorId INNER JOIN races AS T3 ON T3.raceid = T1.raceid WHERE T3.name = 'Monaco Grand Prix' AND T3.year BETWEEN 1980 AND 2010 GROUP BY T2.name, T2.nationality ORDER BY SUM(T1.points) DESC LIMIT 1

merged_df = pd.merge(constructorResults, constructors, on="constructorId", how="inner")

merged_df = pd.merge(merged_df, races, on="raceId", how="inner")

filtered_df = merged_df[(merged_df["name_y"] == "Monaco Grand Prix") & (merged_df["year"].between(1980, 2010))]

grouped_df = filtered_df.groupby(["name_x", "nationality"]).agg({"points": "sum"}).reset_index()

sorted_df = grouped_df.sort_values(by="points", ascending=False)

result = sorted_df.head(1)[["points", "name_x", "nationality"]]


SELECT T2.forename, T2.surname FROM qualifying AS T1 INNER JOIN drivers AS T2 ON T1.driverId = T2.driverId INNER JOIN races AS T3 ON T1.raceid = T3.raceid WHERE q3 IS NOT NULL AND T3.year = 2008 AND T3.circuitId IN (SELECT circuitId FROM circuits WHERE name = 'Marina Bay Street Circuit') ORDER BY CAST(SPLIT_PART(q3, ':', 1) AS INTEGER) * 60 + CAST(SPLIT_PART(SPLIT_PART(q3, ':', 2), '.', 1) AS REAL) + CAST(SPLIT_PART(q3, '.', 2) AS REAL) / 1000 ASC LIMIT 1

circuit_id = circuits[circuits["name"] == "Marina Bay Street Circuit"]["circuitId"].values[0]
races_2008 = races[(races["year"] == 2008) & (races["circuitId"] == circuit_id)]
qualifying_races = qualifying[qualifying["raceId"].isin(races_2008["raceId"]) & qualifying["q3"].notnull()]
qualifying_races["q3_seconds"] = qualifying_races["q3"].apply(lambda x: int(x.split(':')[0]) * 60 + float(x.split(':')[1]))
fastest_qualifying = qualifying_races.loc[qualifying_races["q3_seconds"].idxmin()]
driver_id = fastest_qualifying["driverId"]
result = drivers[drivers["driverId"] == driver_id][["forename", "surname"]]


SELECT COUNT(T1.driverId) FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN status AS T3 ON T1.statusId = T3.statusId WHERE T3.statusId = 3 AND T2.name = 'Canadian Grand Prix' GROUP BY T1.driverId ORDER BY COUNT(T1.driverId) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(results, races, left_on="raceId", right_on="raceId", how="inner")
merged_df = pd.merge(merged_df, status, left_on="statusId", right_on="statusId", how="inner")
filtered_df = merged_df[(merged_df["statusId"] == 3) & (merged_df["name"] == "Canadian Grand Prix")]
accidents_count = filtered_df.groupby("driverId").size()
result = accidents_count.max()


WITH fastest_lap_times AS (SELECT T1.raceId, T1.FastestLapTime, (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) AS time_in_seconds FROM results AS T1 WHERE T1.FastestLapTime IS NOT NULL) SELECT T1.FastestLapTime AS lap_record FROM results AS T1 INNER JOIN races AS T2 ON T1.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId INNER JOIN (SELECT MIN(fastest_lap_times.time_in_seconds) AS min_time_in_seconds FROM fastest_lap_times INNER JOIN races AS T2 ON fastest_lap_times.raceId = T2.raceId INNER JOIN circuits AS T3 ON T2.circuitId = T3.circuitId WHERE T3.country = 'Italy') AS T4 ON (CAST(SPLIT_PART(T1.FastestLapTime, ':', 1) AS REAL) * 60) + (CAST(SPLIT_PART(SPLIT_PART(T1.FastestLapTime, ':', 2), '.', 1) AS REAL)) + (CAST(SPLIT_PART(T1.FastestLapTime, '.', 2) AS REAL) / 1000) = T4.min_time_in_seconds LIMIT 1

results['time_in_seconds'] = results['fastestLapTime'].apply(
lambda x: (int(x.split(':')[0]) * 60) + float(x.split(':')[1]) if x is not None else None
)

fastest_lap_times = results.dropna(subset=['fastestLapTime'])

merged_df = fastest_lap_times.merge(races, on='raceId', how='inner')
merged_df = merged_df.merge(circuits, on='circuitId', how='inner')

italy_laps = merged_df[merged_df['country'] == 'Italy']

min_time_in_seconds = italy_laps['time_in_seconds'].min()

lap_record = italy_laps[italy_laps['time_in_seconds'] == min_time_in_seconds]['fastestLapTime'].iloc[0]
result = lap_record


SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN colour AS T4 ON T1.eye_colour_id = T4.id WHERE T3.power_name = 'Agility' AND T4.colour = 'Blue'

merged_df1 = pd.merge(superhero, hero_power, left_on="id", right_on="hero_id", how="inner")
merged_df2 = pd.merge(merged_df1, superpower, left_on="power_id", right_on="id", how="inner")
merged_df3 = pd.merge(merged_df2, colour, left_on="eye_colour_id", right_on="id", how="inner")
filtered_df = merged_df3[(merged_df3["power_name"] == "Agility") & (merged_df3["colour"] == "Blue")]
result = filtered_df["id_x"].nunique()


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T2.colour = 'Blue' AND T3.colour = 'Blond'

merged_eye_colour = pd.merge(superhero, colour, left_on="eye_colour_id", right_on="id", how="inner")
merged_hair_colour = pd.merge(merged_eye_colour, colour, left_on="hair_colour_id", right_on="id", how="inner", suffixes=('_eye', '_hair'))
filtered_df = merged_hair_colour[(merged_hair_colour["colour_eye"] == "Blue") & (merged_hair_colour["colour_hair"] == "Blond")]
result = filtered_df["superhero_name"]


SELECT superhero_name FROM superhero AS T1 WHERE EXISTS(SELECT 1 FROM hero_power AS T2 INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Super Strength' AND T1.id = T2.hero_id) AND EXISTS(SELECT 1 FROM publisher AS T4 WHERE T4.publisher_name = 'Marvel Comics' AND T1.publisher_id = T4.id)

marvel_heroes = publisher[publisher["publisher_name"] == "Marvel Comics"]
super_strength_power = superpower[superpower["power_name"] == "Super Strength"]

heroes_with_super_strength = hero_power[hero_power["power_id"].isin(super_strength_power["id"])]
marvel_heroes_ids = superhero[superhero["publisher_id"].isin(marvel_heroes["id"])]

result = superhero[(superhero["id"].isin(heroes_with_super_strength["hero_id"])) & (superhero["id"].isin(marvel_heroes_ids["id"]))]["superhero_name"]


SELECT T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN hero_attribute AS T3 ON T1.id = T3.hero_id INNER JOIN attribute AS T4 ON T3.attribute_id = T4.id WHERE T4.attribute_name = 'Speed' ORDER BY T3.attribute_value NULLS FIRST LIMIT 1

merged_df = pd.merge(superhero, publisher, left_on="publisher_id", right_on="id", how="inner")
merged_df = pd.merge(merged_df, hero_attribute, left_on="id_x", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, attribute, left_on="attribute_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["attribute_name"] == "Speed"]
slowest_hero = filtered_df.loc[filtered_df["attribute_value"].idxmin()]
result = slowest_hero["publisher_name"]


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Intelligence' ORDER BY T2.attribute_value NULLS FIRST LIMIT 1

merged_df = pd.merge(superhero, hero_attribute, left_on="id", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, attribute, left_on="attribute_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["attribute_name"] == "Intelligence"]
dumbest_hero = filtered_df.loc[filtered_df["attribute_value"].idxmin(), "superhero_name"]
result = dumbest_hero


SELECT T2.race FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id WHERE T1.superhero_name = 'Copycat'

merged_df = pd.merge(superhero, race, left_on="race_id", right_on="id", how="inner")
result = merged_df.loc[merged_df["superhero_name"] == "Copycat", "race"].iloc[0]


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Death Touch'

merged_df = pd.merge(superhero, hero_power, left_on="id", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, superpower, left_on="power_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["power_name"] == "Death Touch"]
result = filtered_df["superhero_name"].unique()


SELECT (CAST(COUNT(*) AS REAL) * 100 / NULLIF((SELECT COUNT(*) FROM superhero), 0)), CAST(SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) AS REAL) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN alignment AS T3 ON T3.id = T1.alignment_id WHERE T3.alignment = 'Bad'

merged_df = pd.merge(superhero, publisher, left_on="publisher_id", right_on="id", how="inner")
merged_df = pd.merge(merged_df, alignment, left_on="alignment_id", right_on="id", how="inner")
bad_superheroes_df = merged_df[merged_df["alignment"] == "Bad"]
total_superheroes = superhero.shape[0]
percentage_bad_superheroes = (bad_superheroes_df.shape[0] * 100) / total_superheroes
marvel_bad_superheroes = bad_superheroes_df[bad_superheroes_df["publisher_name"] == "Marvel Comics"].shape[0]
result = (percentage_bad_superheroes, marvel_bad_superheroes)


SELECT id FROM publisher WHERE publisher_name = 'Star Trek'

result = publisher.loc[publisher["publisher_name"] == "Star Trek", "id"]


SELECT DISTINCT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.height_cm BETWEEN 170 AND 190 AND T2.colour = 'No Colour'

merged_df = pd.merge(superhero, colour, left_on="eye_colour_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["height_cm"].between(170, 190)) & (merged_df["colour"] == "No Colour")]
result = filtered_df["superhero_name"].unique()


SELECT DISTINCT T3.colour FROM superhero AS T1 INNER JOIN race AS T2 ON T1.race_id = T2.id INNER JOIN colour AS T3 ON T1.hair_colour_id = T3.id WHERE T1.height_cm = 185 AND T2.race = 'Human'

merged_df1 = pd.merge(superhero, race, left_on="race_id", right_on="id", how="inner")
merged_df2 = pd.merge(merged_df1, colour, left_on="hair_colour_id", right_on="id", how="inner")
filtered_df = merged_df2[(merged_df2["height_cm"] == 185) & (merged_df2["race"] == "Human")]
result = filtered_df["colour"].unique()


SELECT DISTINCT T2.power_name FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T1.hero_id = 1

merged_df = pd.merge(hero_power, superpower, left_on="power_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["hero_id"] == 1]
result = filtered_df["power_name"].unique()


SELECT COUNT(T1.hero_id) FROM hero_power AS T1 INNER JOIN superpower AS T2 ON T1.power_id = T2.id WHERE T2.power_name = 'Stealth'

merged_df = pd.merge(hero_power, superpower, left_on="power_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["power_name"] == "Stealth"]
result = filtered_df["hero_id"].nunique()


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T3.id = T2.attribute_id INNER JOIN publisher AS T4 ON T4.id = T1.publisher_id WHERE T4.publisher_name = 'Dark Horse Comics' AND T3.attribute_name = 'Durability' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1

merged_df = pd.merge(superhero, hero_attribute, left_on="id", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, attribute, left_on="attribute_id", right_on="id", how="inner")
merged_df = pd.merge(merged_df, publisher, left_on="publisher_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["publisher_name"] == "Dark Horse Comics") & (merged_df["attribute_name"] == "Durability")]
result = filtered_df.sort_values(by="attribute_value", ascending=False).iloc[0]["superhero_name"]


SELECT T1.superhero_name, T2.publisher_name FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id WHERE T1.eye_colour_id = T1.hair_colour_id AND T1.eye_colour_id = T1.skin_colour_id

merged_df = pd.merge(superhero, publisher, left_on="publisher_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["eye_colour_id"] == merged_df["hair_colour_id"]) & (merged_df["eye_colour_id"] == merged_df["skin_colour_id"])]
result = filtered_df[["superhero_name", "publisher_name"]]


SELECT CAST(COUNT(CASE WHEN T3.colour = 'Blue' THEN T1.id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.gender = 'Female'

merged_df = pd.merge(superhero, gender, left_on="gender_id", right_on="id", how="inner")
merged_df = pd.merge(merged_df, colour, left_on="skin_colour_id", right_on="id", how="inner")
female_superheroes = merged_df[merged_df["gender"] == "Female"]
blue_female_superheroes_count = female_superheroes[female_superheroes["colour"] == "Blue"].shape[0]
total_female_superheroes_count = female_superheroes.shape[0]
result = (blue_female_superheroes_count / total_female_superheroes_count) * 100


SELECT COUNT(T1.power_id) FROM hero_power AS T1 INNER JOIN superhero AS T2 ON T1.hero_id = T2.id WHERE T2.superhero_name = 'Amazo'

merged_df = pd.merge(hero_power, superhero, left_on="hero_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["superhero_name"] == "Amazo"]
result = filtered_df["power_id"].count()


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id AND T1.hair_colour_id = T2.id WHERE T2.colour = 'Black'

merged_df = pd.merge(superhero, colour, left_on=["eye_colour_id", "hair_colour_id"], right_on=["id", "id"], how="inner")
filtered_df = merged_df[merged_df["colour"] == "Black"]
result = filtered_df["superhero_name"].tolist()


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id WHERE T2.alignment = 'Neutral'

merged_df = pd.merge(superhero, alignment, left_on="alignment_id", right_on="id", how="inner")
neutral_superheroes = merged_df[merged_df["alignment"] == "Neutral"]
result = neutral_superheroes["superhero_name"]


SELECT COUNT(T1.hero_id) FROM hero_attribute AS T1 INNER JOIN attribute AS T2 ON T1.attribute_id = T2.id WHERE T2.attribute_name = 'Strength' AND T1.attribute_value = (SELECT MAX(attribute_value) FROM hero_attribute)

merged_df = pd.merge(hero_attribute, attribute, left_on="attribute_id", right_on="id", how="inner")
strength_df = merged_df[merged_df["attribute_name"] == "Strength"]
max_value = strength_df["attribute_value"].max()
result = strength_df[strength_df["attribute_value"] == max_value]["hero_id"].nunique()


SELECT CAST(COUNT(CASE WHEN T3.gender = 'Female' AND T2.publisher_name = 'Marvel Comics' THEN 1 ELSE NULL END) AS REAL) / NULLIF(COUNT(CASE WHEN T3.gender = 'Female' THEN 1 ELSE NULL END), 0) * 100 FROM superhero AS T1 LEFT JOIN publisher AS T2 ON T1.publisher_id = T2.id INNER JOIN gender AS T3 ON T1.gender_id = T3.id

merged_df = pd.merge(superhero, publisher, left_on="publisher_id", right_on="id", how="left")
merged_df = pd.merge(merged_df, gender, left_on="gender_id", right_on="id", how="inner")
female_heroes = merged_df[merged_df["gender"] == "Female"]
female_marvel_heroes = female_heroes[female_heroes["publisher_name"] == "Marvel Comics"]
percent_female_marvel_heroes = (female_marvel_heroes.shape[0] / female_heroes.shape[0]) * 100
result = percent_female_marvel_heroes


SELECT CAST(SUM(height_cm) AS REAL) / NULLIF(COUNT(id), 0) FROM superhero

result = superhero["height_cm"].sum() / superhero["id"].count()


SELECT T3.power_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T1.superhero_name = 'Abomination'

merged_df_1 = pd.merge(superhero, hero_power, left_on="id", right_on="hero_id", how="inner")
merged_df_2 = pd.merge(merged_df_1, superpower, left_on="power_id", right_on="id", how="inner")
result = merged_df_2[merged_df_2["superhero_name"] == "Abomination"]["power_name"]


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T3.attribute_name = 'Speed' ORDER BY T2.attribute_value DESC NULLS LAST LIMIT 1

merged_df = pd.merge(superhero, hero_attribute, left_on="id", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, attribute, left_on="attribute_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["attribute_name"] == "Speed"]
result = filtered_df.loc[filtered_df["attribute_value"].idxmax(), "superhero_name"]


SELECT T3.attribute_name, T2.attribute_value FROM superhero AS T1 INNER JOIN hero_attribute AS T2 ON T1.id = T2.hero_id INNER JOIN attribute AS T3 ON T2.attribute_id = T3.id WHERE T1.superhero_name = '3-D Man'

merged_df_1 = pd.merge(superhero, hero_attribute, left_on="id", right_on="hero_id", how="inner")
merged_df_2 = pd.merge(merged_df_1, attribute, left_on="attribute_id", right_on="id", how="inner")
filtered_df = merged_df_2[merged_df_2["superhero_name"] == "3-D Man"]
result = filtered_df[["attribute_name", "attribute_value"]]


SELECT CAST(COUNT(CASE WHEN T2.colour = 'Blue' THEN 1 ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id

merged_df = pd.merge(superhero, colour, left_on="eye_colour_id", right_on="id", how="inner")
blue_eyes_count = merged_df[merged_df["colour"] == "Blue"]["superhero_name"].count()
total_superheroes = merged_df["superhero_name"].count()
result = (blue_eyes_count / total_superheroes) * 100.0


SELECT CAST(COUNT(CASE WHEN T2.gender = 'Male' THEN T1.id ELSE NULL END) AS REAL) / NULLIF(COUNT(CASE WHEN T2.gender = 'Female' THEN T1.id ELSE NULL END), 0) FROM superhero AS T1 INNER JOIN gender AS T2 ON T1.gender_id = T2.id

merged_df = pd.merge(superhero, gender, left_on="gender_id", right_on="id", how="inner")
male_count = merged_df[merged_df["gender"] == "Male"].shape[0]
female_count = merged_df[merged_df["gender"] == "Female"].shape[0]
result = float(male_count) / female_count


SELECT T2.colour FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.full_name = 'Karen Beecher-Duncan'

merged_df = pd.merge(superhero, colour, left_on="eye_colour_id", right_on="id", how="inner")
result = merged_df[merged_df["full_name"] == "Karen Beecher-Duncan"]["colour"].iloc[0]


SELECT SUM(CASE WHEN T2.id = 7 THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.id = 1 THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN colour AS T2 ON T1.eye_colour_id = T2.id WHERE T1.weight_kg = 0 OR T1.weight_kg IS NULL

merged_df = pd.merge(superhero, colour, left_on="eye_colour_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["weight_kg"] == 0) | (merged_df["weight_kg"].isnull())]
blue_eyes_count = (filtered_df["id_y"] == 7).sum()
no_eye_color_count = (filtered_df["id_y"] == 1).sum()
result = blue_eyes_count - no_eye_color_count


SELECT COUNT(T1.id) FROM superhero AS T1 INNER JOIN alignment AS T2 ON T1.alignment_id = T2.id INNER JOIN colour AS T3 ON T1.skin_colour_id = T3.id WHERE T2.alignment = 'Bad' AND T3.colour = 'Green'

merged_df = pd.merge(superhero, alignment, left_on="alignment_id", right_on="id", how="inner")
merged_df = pd.merge(merged_df, colour, left_on="skin_colour_id", right_on="id", how="inner")
filtered_df = merged_df[(merged_df["alignment"] == "Bad") & (merged_df["colour"] == "Green")]
result = filtered_df["id_x"].count()


SELECT T1.superhero_name FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id WHERE T3.power_name = 'Wind Control' ORDER BY T1.superhero_name NULLS FIRST

merged_df = pd.merge(superhero, hero_power, left_on="id", right_on="hero_id", how="inner")
merged_df = pd.merge(merged_df, superpower, left_on="power_id", right_on="id", how="inner")
filtered_df = merged_df[merged_df["power_name"] == "Wind Control"]
result = filtered_df["superhero_name"].sort_values().unique()


SELECT T4.gender FROM superhero AS T1 INNER JOIN hero_power AS T2 ON T1.id = T2.hero_id INNER JOIN superpower AS T3 ON T2.power_id = T3.id INNER JOIN gender AS T4 ON T1.gender_id = T4.id WHERE T3.power_name = 'Phoenix Force'

merged_df_1 = pd.merge(superhero, hero_power, left_on="id", right_on="hero_id", how="inner")
merged_df_2 = pd.merge(merged_df_1, superpower, left_on="power_id", right_on="id", how="inner")
merged_df_3 = pd.merge(merged_df_2, gender, left_on="gender_id", right_on="id", how="inner")
filtered_df = merged_df_3[merged_df_3["power_name"] == "Phoenix Force"]
result = filtered_df["gender"]


SELECT SUM(CASE WHEN T2.publisher_name = 'DC Comics' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.publisher_name = 'Marvel Comics' THEN 1 ELSE 0 END) FROM superhero AS T1 INNER JOIN publisher AS T2 ON T1.publisher_id = T2.id

merged_df = pd.merge(superhero, publisher, left_on="publisher_id", right_on="id", how="inner")
dc_count = (merged_df["publisher_name"] == "DC Comics").sum()
marvel_count = (merged_df["publisher_name"] == "Marvel Comics").sum()
result = dc_count - marvel_count


SELECT DisplayName FROM users WHERE TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011'

users['CreationDate'] = pd.to_datetime(users['CreationDate'], errors='coerce')
result = users[users["CreationDate"].dt.year == 2011]["DisplayName"]


SELECT COUNT(T1.id) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T2.DisplayName = 'csgillespie'

merged_df = pd.merge(posts, users, left_on="OwnerUserId", right_on="Id", how="inner")
filtered_df = merged_df[merged_df["DisplayName"] == "csgillespie"]
result = filtered_df["Id_x"].count()


SELECT CAST(SUM(CASE WHEN T2.Age > 65 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score > 5

merged_df = pd.merge(posts, users, left_on="OwnerUserId", right_on="Id", how="inner")
filtered_df = merged_df[merged_df["Score"] > 5]
elder_count = filtered_df[filtered_df["Age"] > 65].shape[0]
total_count = filtered_df.shape[0]
result = (elder_count / total_count) * 100


SELECT T1.FavoriteCount FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId WHERE T2.CreationDate = '2014-04-23 20:29:39.0' AND T2.UserId = 3025

merged_df = pd.merge(posts, comments, left_on="Id", right_on="PostId", how="inner")
filtered_df = merged_df[(merged_df["CreationDate"] == "2014-04-23 20:29:39.0") & (merged_df["UserId"] == 3025)]
result = filtered_df["FavoriteCount"].iloc[0]


SELECT CASE WHEN T2.ClosedDate IS NULL THEN 'NOT well-finished' ELSE 'well-finished' END AS resylt FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T1.UserId = 23853 AND T1.CreationDate = '2013-07-12 09:08:18.0'

merged_df = pd.merge(comments, posts, left_on="PostId", right_on="Id", how="inner")
filtered_df = merged_df[(merged_df["UserId"] == 23853) & (merged_df["CreationDate"] == '2013-07-12 09:08:18.0')]
result = 'well-finished' if not filtered_df["ClosedDate"].isnull().all() else 'NOT well-finished'


SELECT COUNT(T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Tiago Pasqualini'

merged_df = pd.merge(users, posts, left_on="Id", right_on="OwnerUserId", how="inner")
filtered_df = merged_df[merged_df["DisplayName"] == "Tiago Pasqualini"]
result = filtered_df["Id_x"].count()


SELECT T1.DisplayName FROM users AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.UserId WHERE T2.Id = 6347

merged_df = pd.merge(users, votes, left_on="Id", right_on="UserId", how="inner")
filtered_df = merged_df[merged_df["Id_y"] == 6347]
result = filtered_df["DisplayName"].iloc[0]


SELECT CAST(COUNT(DISTINCT T2.Id) AS REAL) / NULLIF(COUNT(DISTINCT T1.Id), 0) FROM votes AS T1 INNER JOIN posts AS T2 ON T1.UserId = T2.OwnerUserId WHERE T1.UserId = 24

merged_df = pd.merge(votes, posts, left_on="UserId", right_on="OwnerUserId", how="inner")
filtered_df = merged_df[merged_df["UserId"] == 24]
result = filtered_df["Id_y"].nunique() / filtered_df["Id_x"].nunique()


SELECT ViewCount FROM posts WHERE Title = 'Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer'

result = posts.loc[posts["Title"] == "Integration of Weka and/or RapidMiner into Informatica PowerCenter/Developer", "ViewCount"].iloc[0]


SELECT Text FROM comments WHERE Score = 17

result = comments[comments["Score"] == 17]["Text"]


SELECT T1.DisplayName FROM users AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.UserId WHERE T2.Text = 'thank you user93!'

merged_df = pd.merge(users, comments, left_on="Id", right_on="UserId", how="inner")
filtered_df = merged_df[merged_df["Text"] == "thank you user93!"]
result = filtered_df["DisplayName"].iloc[0]


SELECT T1.DisplayName, T1.Reputation FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T2.Title = 'Understanding what Dassault iSight is doing?'

merged_df = pd.merge(users, posts, left_on="Id", right_on="OwnerUserId", how="inner")
filtered_df = merged_df[merged_df["Title"] == 'Understanding what Dassault iSight is doing?']
result = filtered_df[["DisplayName", "Reputation"]]


SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Title = 'Open source tools for visualizing multi-dimensional data?'

merged_df = pd.merge(posts, users, left_on="OwnerUserId", right_on="Id", how="inner")
filtered_df = merged_df[merged_df["Title"] == 'Open source tools for visualizing multi-dimensional data?']
result = filtered_df["DisplayName"].iloc[0]


SELECT T2.Comment FROM posts AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.PostId WHERE T1.Title = 'Why square the difference instead of taking the absolute value in standard deviation?'

merged_df = pd.merge(posts, postHistory, left_on="Id", right_on="PostId", how="inner")
filtered_df = merged_df[merged_df["Title"] == 'Why square the difference instead of taking the absolute value in standard deviation?']
result = filtered_df["Comment"]


SELECT T3.DisplayName FROM posts AS T1 INNER JOIN votes AS T2 ON T1.Id = T2.PostId INNER JOIN users AS T3 ON T3.Id = T2.UserId WHERE T2.BountyAmount = 50 AND T1.Title LIKE '%variance%'

merged_df_1 = pd.merge(posts, votes, left_on="Id", right_on="PostId", how="inner")
merged_df_2 = pd.merge(merged_df_1, users, left_on="UserId", right_on="Id", how="inner")
filtered_df = merged_df_2[(merged_df_2["BountyAmount"] == 50) & (merged_df_2["Title"].str.contains("variance", case=False))]
result = filtered_df["DisplayName"]