SELECT T2.UserId FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.Views >= 100 GROUP BY T2.UserId HAVING COUNT(DISTINCT T2.PostHistoryTypeId) = 1

merged_df = pd.merge(users, postHistory, left_on="Id", right_on="UserId", how="inner")
merged_df = pd.merge(merged_df, posts, left_on="PostId", right_on="Id", how="inner")
filtered_df = merged_df[merged_df["Views"] >= 100]
grouped_df = filtered_df.groupby("UserId").agg({"PostHistoryTypeId": pd.Series.nunique})
result = grouped_df[grouped_df["PostHistoryTypeId"] == 1].index.tolist()


SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) - CAST(SUM(CASE WHEN TO_CHAR(CAST(Date AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(Id), 0) FROM badges WHERE Name = 'Student'

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

badges_filtered = badges[badges["Name"] == "Student"]

count_2010 = (badges_filtered["Date"].dt.year == 2010).sum()

count_2011 = (badges_filtered["Date"].dt.year == 2011).sum()

total_count = badges_filtered["Id"].count()

percentage_2010 = (count_2010 / total_count) * 100

percentage_2011 = (count_2011 / total_count) * 100

result = percentage_2010 - percentage_2011


SELECT AVG(T1.UpVotes), AVG(T1.Age) FROM users AS T1 INNER JOIN (SELECT OwnerUserId, COUNT(*) AS post_count FROM posts GROUP BY OwnerUserId HAVING COUNT(*) > 10) AS T2 ON T1.Id = T2.OwnerUserId

post_counts = posts.groupby("OwnerUserId").size().reset_index(name="post_count")
filtered_users = post_counts[post_counts["post_count"] > 10]
merged_df = pd.merge(users, filtered_users, left_on="Id", right_on="OwnerUserId", how="inner")
average_upvotes = merged_df["UpVotes"].mean()
average_age = merged_df["Age"].mean()
result = (average_upvotes, average_age)


SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2010' THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN TO_CHAR(CAST(CreationDate AS TIMESTAMP), 'YYYY') = '2011' THEN 1 ELSE 0 END), 0) FROM votes

votes['Year'] = pd.to_datetime(votes['CreationDate']).dt.year
votes_2010 = votes[votes['Year'] == 2010]['Id'].count()
votes_2011 = votes[votes['Year'] == 2011]['Id'].count()
result = float(votes_2010) / votes_2011


SELECT T1.DisplayName FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T2.PostId = T3.Id WHERE T1.DisplayName = 'Harvey Motulsky' OR T1.DisplayName = 'Noah Snyder' GROUP BY T1.DisplayName ORDER BY SUM(T3.ViewCount) DESC NULLS LAST LIMIT 1

merged_df = pd.merge(users, postHistory, left_on="Id", right_on="UserId", how="inner")
merged_df = pd.merge(merged_df, posts, left_on="PostId", right_on="Id", how="inner")
filtered_df = merged_df[(merged_df["DisplayName"] == "Harvey Motulsky") | (merged_df["DisplayName"] == "Noah Snyder")]
grouped_df = filtered_df.groupby("DisplayName")["ViewCount"].sum().reset_index()
result = grouped_df.loc[grouped_df["ViewCount"].idxmax(), "DisplayName"]


SELECT T3.Tags FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId WHERE T1.DisplayName = 'Mark Meckes' AND T3.CommentCount = 0

merged_df1 = pd.merge(users, postHistory, left_on="Id", right_on="UserId", how="inner")
merged_df2 = pd.merge(merged_df1, posts, left_on="PostId", right_on="Id", how="inner")
filtered_df = merged_df2[(merged_df2["DisplayName"] == "Mark Meckes") & (merged_df2["CommentCount"] == 0)]
result = filtered_df["Tags"]


SELECT CAST(SUM(CASE WHEN T3.TagName = 'r' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN tags AS T3 ON T3.ExcerptPostId = T2.PostId WHERE T1.DisplayName = 'Community'

merged_df = pd.merge(users, postHistory, left_on="Id", right_on="UserId", how="inner")
merged_df = pd.merge(merged_df, tags, left_on="PostId", right_on="ExcerptPostId", how="inner")
community_posts = merged_df[merged_df["DisplayName"] == "Community"]
r_tag_count = community_posts["TagName"].eq("r").sum()
total_posts = community_posts["Id_x"].count()
result = (r_tag_count / total_posts) * 100


SELECT SUM(CASE WHEN T1.DisplayName = 'Mornington' THEN T3.ViewCount ELSE 0 END) - SUM(CASE WHEN T1.DisplayName = 'Amos' THEN T3.ViewCount ELSE 0 END) AS diff FROM users AS T1 INNER JOIN postHistory AS T2 ON T1.Id = T2.UserId INNER JOIN posts AS T3 ON T3.Id = T2.PostId

merged_df = pd.merge(users, postHistory, left_on="Id", right_on="UserId", how="inner")
merged_df = pd.merge(merged_df, posts, left_on="PostId", right_on="Id", how="inner")
mornington_views = merged_df.loc[merged_df["DisplayName"] == "Mornington", "ViewCount"].sum()
amos_views = merged_df.loc[merged_df["DisplayName"] == "Amos", "ViewCount"].sum()
result = mornington_views - amos_views


SELECT COUNT(DISTINCT T1.Id) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.Location = 'United Kingdom' AND T2.FavoriteCount >= 4

merged_df = pd.merge(users, posts, left_on="Id", right_on="OwnerUserId", how="inner")
filtered_df = merged_df[(merged_df["Location"] == "United Kingdom") & (merged_df["FavoriteCount"] >= 4)]
result = filtered_df["Id_x"].nunique()


SELECT T2.Id, T2.Title FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId WHERE T1.DisplayName = 'Harvey Motulsky' ORDER BY T2.ViewCount DESC NULLS LAST LIMIT 1

merged_df = pd.merge(users, posts, left_on="Id", right_on="OwnerUserId", how="inner")
filtered_df = merged_df[merged_df["DisplayName"] == "Harvey Motulsky"]
sorted_df = filtered_df.sort_values(by="ViewCount", ascending=False)
result = sorted_df[["Id_y", "Title"]].head(1).rename(columns={"Id_y": "Id"})


SELECT CAST(SUM(CASE WHEN TO_CHAR(CAST(T2.CreaionDate AS TIMESTAMP), 'YYYY') = '2011' AND T1.Reputation > 1000 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId

posts['CreaionDate'] = pd.to_datetime(posts['CreaionDate'], errors='coerce')

merged_df = pd.merge(users, posts, left_on="Id", right_on="OwnerUserId", how="inner")

condition = (merged_df["CreaionDate"].dt.year == 2011) & (merged_df["Reputation"] > 1000)

percentage = (condition.sum() / len(merged_df)) * 100

result = percentage


SELECT T2.ViewCount, T3.DisplayName FROM postHistory AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id INNER JOIN users AS T3 ON T2.LastEditorUserId = T3.Id WHERE T1.Text = 'Computer Game Datasets'

merged_df1 = pd.merge(postHistory, posts, left_on="PostId", right_on="Id", how="inner")
merged_df2 = pd.merge(merged_df1, users, left_on="LastEditorUserId", right_on="Id", how="inner")
filtered_df = merged_df2[merged_df2["Text"] == "Computer Game Datasets"]
result = filtered_df[["ViewCount", "DisplayName"]]


SELECT COUNT(T2.Id) FROM posts AS T1 INNER JOIN comments AS T2 ON T1.Id = T2.PostId GROUP BY T1.Id ORDER BY T1.Score DESC NULLS LAST LIMIT 1

merged_df = pd.merge(posts, comments, left_on="Id", right_on="PostId", how="inner")

grouped_df = merged_df.groupby("Id_x").size().reset_index(name='comment_count')

max_score_post_id = posts.loc[posts['Score'].idxmax(), 'Id']

result = grouped_df.loc[grouped_df['Id_x'] == max_score_post_id, 'comment_count'].iloc[0]


SELECT CAST(SUM(CASE WHEN T2.Score > 50 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.Id), 0) FROM users AS T1 INNER JOIN posts AS T2 ON T1.Id = T2.OwnerUserId INNER JOIN (SELECT MAX(Reputation) AS max_reputation FROM users) AS T3 ON T1.Reputation = T3.max_reputation

max_reputation = users["Reputation"].max()
influential_user_posts = posts[posts["OwnerUserId"].isin(users[users["Reputation"] == max_reputation]["Id"])]
count_high_score = influential_user_posts[influential_user_posts["Score"] > 50].shape[0]
total_posts = influential_user_posts.shape[0]
result = (count_high_score / total_posts) * 100


SELECT ExcerptPostId, WikiPostId FROM tags WHERE TagName = 'sample'

result = tags.loc[tags["TagName"] == "sample", ["ExcerptPostId", "WikiPostId"]]


SELECT COUNT(T1.id) FROM comments AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.CommentCount = 1 AND T1.Score = 0

merged_df = pd.merge(comments, posts, left_on="PostId", right_on="Id", how="inner")
filtered_df = merged_df[(merged_df["CommentCount"] == 1) & (merged_df["Score_x"] == 0)]
result = len(filtered_df)


SELECT id FROM cards WHERE NOT cardKingdomFoilId IS NULL AND NOT cardKingdomId IS NULL

result = cards[(cards["cardKingdomFoilId"].notnull()) & (cards["cardKingdomId"].notnull())]["id"]


SELECT id FROM cards WHERE borderColor = 'borderless' AND (cardKingdomFoilId IS NULL OR cardKingdomId IS NULL)

result = cards[(cards["borderColor"] == "borderless") & ((cards["cardKingdomFoilId"].isnull()) | (cards["cardKingdomId"].isnull()))]["id"]


SELECT DISTINCT T1.id FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.format = 'gladiator' AND T2.status = 'Banned' AND T1.rarity = 'mythic'

merged_df = pd.merge(cards, legalities, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["format"] == "gladiator") & (merged_df["status"] == "Banned") & (merged_df["rarity"] == "mythic")]
result = filtered_df["id_x"].unique()


SELECT DISTINCT T2.status FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.type = 'Artifact' AND T2.format = 'vintage' AND T1.side IS NULL

merged_df = pd.merge(cards, legalities, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["type"] == "Artifact") & (merged_df["format"] == "vintage") & (merged_df["side"].isnull())]
result = filtered_df["status"].unique()


SELECT DISTINCT borderColor FROM cards WHERE name = 'Ancestor''s Chosen'

result = cards[cards["name"] == "Ancestor's Chosen"]["borderColor"].unique()


SELECT CAST(SUM(CASE WHEN borderColor = 'borderless' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards

total_count = len(cards)
borderless_count = len(cards[cards["borderColor"] == "borderless"])
result = (borderless_count / total_count) * 100


SELECT COUNT(id) FROM cards WHERE originalType = 'Summon - Angel' AND subtypes <> 'Angel'

filtered_df = cards[(cards["originalType"] == "Summon - Angel") & (cards["subtypes"] != "Angel")]
result = filtered_df["id"].count()


SELECT id FROM cards WHERE duelDeck = 'a'

result = cards[cards["duelDeck"] == "a"]["id"]


SELECT COUNT(DISTINCT T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T2.status = 'Banned' AND T1.borderColor = 'white'

merged_df = pd.merge(cards, legalities, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["status"] == "Banned") & (merged_df["borderColor"] == "white")]
result = filtered_df["id_x"].nunique()


SELECT DISTINCT T1.name FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.originalType = 'Artifact' AND T1.colors = 'B'

merged_df = pd.merge(cards, foreign_data, on="uuid", how="inner")
filtered_df = merged_df[(merged_df["originalType"] == "Artifact") & (merged_df["colors"] == "B")]
result = filtered_df["name_x"].unique()


SELECT manaCost FROM cards WHERE availability = 'mtgo,paper' AND borderColor = 'black' AND frameVersion = '2003' AND layout = 'normal'

result = cards[(cards["availability"] == "mtgo,paper") &
(cards["borderColor"] == "black") &
(cards["frameVersion"] == "2003") &
(cards["layout"] == "normal")]["manaCost"]


SELECT CAST(SUM(CASE WHEN isTextless = 0 AND isStorySpotlight = 1 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(id), 0) FROM cards

total_cards = len(cards)
story_spotlight_text_cards = len(cards[(cards["isTextless"] == 0) & (cards["isStorySpotlight"] == 1)])
result = (story_spotlight_text_cards / total_cards) * 100


SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T1.code = T2.setCode WHERE T2.language = 'Portuguese (Brazil)' AND T1.block = 'Commander'

merged_df = pd.merge(sets, set_translations, left_on="code", right_on="setCode", how="inner")
filtered_df = merged_df[(merged_df["language"] == "Portuguese (Brazil)") & (merged_df["block"] == "Commander")]
result = filtered_df["id_x"].count()


SELECT T1.subtypes, T1.supertypes FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T2.language = 'German' AND NOT T1.subtypes IS NULL AND NOT T1.supertypes IS NULL

merged_df = pd.merge(cards, foreign_data, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["language"] == "German") & (merged_df["subtypes"].notnull()) & (merged_df["supertypes"].notnull())]
result = filtered_df[["subtypes", "supertypes"]]


SELECT COUNT(T1.id) FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid INNER JOIN rulings AS T3 ON T1.uuid = T3.uuid WHERE T2.format = 'premodern' AND T3.text = 'This is a triggered mana ability.' AND T1.Side IS NULL

merged_df = pd.merge(cards, legalities, on="uuid", how="inner")

merged_df = pd.merge(merged_df, rulings, on="uuid", how="inner")

filtered_df = merged_df[
(merged_df["format"] == "premodern") &
(merged_df["text_y"] == "This is a triggered mana ability.") &
(merged_df["side"].isnull())
]

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


SELECT name FROM foreign_data WHERE uuid IN (SELECT uuid FROM cards WHERE types = 'Creature' AND layout = 'normal' AND borderColor = 'black' AND artist = 'Matthew D. Wilson') AND language = 'French'

filtered_cards = cards[(cards["types"] == "Creature") & (cards["layout"] == "normal") & (cards["borderColor"] == "black") & (cards["artist"] == "Matthew D. Wilson")]
filtered_foreign_data = foreign_data[(foreign_data["uuid"].isin(filtered_cards["uuid"])) & (foreign_data["language"] == "French")]
result = filtered_foreign_data["name"]


SELECT CAST(SUM(CASE WHEN T2.language = 'French' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN foreign_data AS T2 ON T1.uuid = T2.uuid WHERE T1.power IS NULL OR T1.power = '*'

merged_df = pd.merge(cards, foreign_data, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["power"].isnull()) | (merged_df["power"] == '*')]
french_count = filtered_df[filtered_df["language"] == "French"].shape[0]
total_count = filtered_df.shape[0]
result = (french_count / total_count) * 100


SELECT DISTINCT language FROM foreign_data WHERE name = 'A Pedra Fellwar'

result = foreign_data[foreign_data["name"] == "A Pedra Fellwar"]["language"].unique()


SELECT name FROM cards WHERE name IN ('Serra Angel', 'Shrine Keeper') ORDER BY convertedManaCost DESC NULLS LAST LIMIT 1

result = cards[cards["name"].isin(["Serra Angel", "Shrine Keeper"])].sort_values(by="convertedManaCost", ascending=False).head(1)["name"].iloc[0]


SELECT translation FROM set_translations WHERE setCode IN (SELECT setCode FROM cards WHERE name = 'Ancestor''s Chosen') AND language = 'Italian'

set_codes = cards[cards["name"] == "Ancestor's Chosen"]["setCode"].unique()
result = set_translations[(set_translations["setCode"].isin(set_codes)) & (set_translations["language"] == "Italian")]["translation"]


SELECT T2.translation FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE T1.name = 'Eighth Edition' AND T2.language = 'Chinese Simplified'

merged_df = pd.merge(set_translations, sets, left_on="setCode", right_on="code", how="inner")
filtered_df = merged_df[(merged_df["name"] == "Eighth Edition") & (merged_df["language"] == "Chinese Simplified")]
result = filtered_df["translation"].iloc[0]


SELECT COUNT(T1.id) FROM sets AS T1 INNER JOIN set_translations AS T2 ON T2.setCode = T1.code WHERE NOT T2.translation IS NULL AND T1.baseSetSize < 100 AND T2.language = 'Italian'

merged_df = pd.merge(set_translations, sets, left_on="setCode", right_on="code", how="inner")
filtered_df = merged_df[(merged_df["translation"].notnull()) & (merged_df["baseSetSize"] < 100) & (merged_df["language"] == "Italian")]
result = len(filtered_df)


SELECT SUM(CASE WHEN T1.power = '*' OR T1.power IS NULL THEN 1 ELSE 0 END) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap' AND T1.convertedManaCost > 5

merged_df = pd.merge(cards, sets, left_on="setCode", right_on="code", how="inner")
filtered_df = merged_df[(merged_df["name_y"] == "Coldsnap") & (merged_df["convertedManaCost"] > 5)]
result = ((filtered_df["power"] == '*') | (filtered_df["power"].isnull())).sum()


SELECT DISTINCT T1.text FROM foreign_data AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid INNER JOIN sets AS T3 ON T3.code = T2.setCode WHERE T3.name = 'Coldsnap' AND T1.language = 'Italian'

merged_df_1 = pd.merge(foreign_data, cards, on="uuid", how="inner")

merged_df_2 = pd.merge(merged_df_1, sets, left_on="setCode", right_on="code", how="inner")

filtered_df = merged_df_2[(merged_df_2["name"] == "Coldsnap") & (merged_df_2["language"] == "Italian")]

result = filtered_df["text_x"].drop_duplicates()


SELECT CAST(SUM(CASE WHEN T1.convertedManaCost = 7 THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'

merged_df = pd.merge(cards, sets, left_on="setCode", right_on="code", how="inner")

filtered_df = merged_df[merged_df["name_y"] == "Coldsnap"]

percentage = (filtered_df["convertedManaCost"] == 7).sum() * 100 / filtered_df["id_x"].count()

result = percentage


SELECT CAST(SUM(CASE WHEN NOT T1.cardKingdomFoilId IS NULL AND NOT T1.cardKingdomId IS NULL THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.id), 0) FROM cards AS T1 INNER JOIN sets AS T2 ON T2.code = T1.setCode WHERE T2.name = 'Coldsnap'

merged_df = pd.merge(cards, sets, left_on="setCode", right_on="code", how="inner")
filtered_df = merged_df[merged_df["name_y"] == "Coldsnap"]
incredibly_powerful_count = ((filtered_df["cardKingdomFoilId"].notnull()) & (filtered_df["cardKingdomId"].notnull())).sum()
total_count = filtered_df["id_x"].count()
result = (incredibly_powerful_count / total_count) * 100


SELECT T1.name, T2.format FROM cards AS T1 INNER JOIN legalities AS T2 ON T2.uuid = T1.uuid WHERE T1.edhrecRank = 1 AND T2.status = 'Banned' GROUP BY T1.name, T2.format

merged_df = pd.merge(cards, legalities, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[(merged_df["edhrecRank"] == 1) & (merged_df["status"] == "Banned")]
result = filtered_df[["name", "format"]].drop_duplicates()


SELECT DISTINCT T2.name, CASE WHEN T1.status = 'Legal' THEN T1.format ELSE NULL END FROM legalities AS T1 INNER JOIN cards AS T2 ON T2.uuid = T1.uuid WHERE T2.setCode IN (SELECT code FROM sets WHERE name = 'Hour of Devastation')

hour_of_devastation_codes = sets.loc[sets["name"] == "Hour of Devastation", "code"]
cards_in_hour_of_devastation = cards[cards["setCode"].isin(hour_of_devastation_codes)]
merged_df = pd.merge(legalities, cards_in_hour_of_devastation, left_on="uuid", right_on="uuid", how="inner")
result = merged_df.loc[merged_df["status"] == "Legal", ["name", "format"]].drop_duplicates()


SELECT DISTINCT T1.frameVersion, T1.name, CASE WHEN T2.status = 'Banned' THEN T1.name ELSE 'NO' END FROM cards AS T1 INNER JOIN legalities AS T2 ON T1.uuid = T2.uuid WHERE T1.artist = 'Allen Williams'

merged_df = pd.merge(cards, legalities, left_on="uuid", right_on="uuid", how="inner")
filtered_df = merged_df[merged_df["artist"] == "Allen Williams"]
filtered_df["banned_status"] = filtered_df["status"].apply(lambda x: filtered_df["name"] if x == "Banned" else "NO")
result = filtered_df[["frameVersion", "name", "banned_status"]].drop_duplicates()


SELECT AVG(oxygen_count) FROM (SELECT T1.molecule_id, COUNT(T1.element) AS oxygen_count FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '-' AND T1.element = 'o' GROUP BY T1.molecule_id) AS oxygen_counts

merged_df = pd.merge(atom, bond, on="molecule_id", how="inner")
filtered_df = merged_df[(merged_df["bond_type"] == "-") & (merged_df["element"] == "o")]
oxygen_counts = filtered_df.groupby("molecule_id").size().reset_index(name="oxygen_count")
result = oxygen_counts["oxygen_count"].mean()


SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '#' AND T2.label = '+'

merged_df = pd.merge(bond, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[(merged_df["bond_type"] == "#") & (merged_df["label"] == "+")]
result = filtered_df["molecule_id"].unique()


SELECT CAST(COUNT(DISTINCT CASE WHEN T1.element = 'c' THEN T1.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T1.atom_id), 0) FROM atom AS T1 INNER JOIN bond AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.bond_type = '='

merged_df = pd.merge(atom, bond, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[merged_df["bond_type"] == "="]
carbon_count = filtered_df[filtered_df["element"] == "c"]["atom_id"].nunique()
total_count = filtered_df["atom_id"].nunique()
result = (carbon_count / total_count) * 100


SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id = 'TR004_8_9'

merged_df = pd.merge(atom, connected, left_on="atom_id", right_on="atom_id", how="inner")
filtered_df = merged_df[merged_df["bond_id"] == "TR004_8_9"]
result = filtered_df["element"].unique()


SELECT T.element FROM (SELECT T1.element, COUNT(DISTINCT T1.molecule_id) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '-' GROUP BY T1.element ORDER BY COUNT(DISTINCT T1.molecule_id) ASC NULLS FIRST LIMIT 1) AS t

merged_df = pd.merge(atom, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[merged_df["label"] == "-"]
element_counts = filtered_df.groupby("element")["molecule_id"].nunique()
least_numerous_element = element_counts.idxmin()
result = least_numerous_element


SELECT T1.bond_type FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.atom_id = 'TR004_8' AND T2.atom_id2 = 'TR004_20' OR T2.atom_id2 = 'TR004_8' AND T2.atom_id = 'TR004_20'

merged_df = pd.merge(bond, connected, left_on="bond_id", right_on="bond_id", how="inner")
filtered_df = merged_df[((merged_df["atom_id"] == "TR004_8") & (merged_df["atom_id2"] == "TR004_20")) | ((merged_df["atom_id"] == "TR004_20") & (merged_df["atom_id2"] == "TR004_8"))]
result = filtered_df["bond_type"]


SELECT 100 - CAST(COUNT(DISTINCT CASE WHEN T1.element = 'f' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+'

merged_df = pd.merge(atom, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
carcinogenic_df = merged_df[merged_df["label"] == "+"]
fluorine_molecules = carcinogenic_df[carcinogenic_df["element"] == "f"]["molecule_id"].nunique()
total_carcinogenic_molecules = carcinogenic_df["molecule_id"].nunique()
result = 100 - (fluorine_molecules * 100 / total_carcinogenic_molecules)


SELECT CAST(COUNT(DISTINCT CASE WHEN T2.label = '+' THEN T2.molecule_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(DISTINCT T2.molecule_id), 0) FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id INNER JOIN bond AS T3 ON T2.molecule_id = T3.molecule_id WHERE T3.bond_type = '#'

merged_df = pd.merge(atom, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
merged_df = pd.merge(merged_df, bond, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[merged_df["bond_type"] == "#"]
carcinogenic_count = filtered_df[filtered_df["label"] == "+"].molecule_id.nunique()
total_count = filtered_df.molecule_id.nunique()
result = (carcinogenic_count * 100) / total_count


SELECT ROUND(CAST((CAST(COUNT(CASE WHEN t.label = '+' THEN t.molecule_id ELSE NULL END) AS REAL) / NULLIF(COUNT(t.molecule_id), 0) * 100) AS NUMERIC), 3) AS percentage FROM molecule t

total_molecules = molecule["molecule_id"].count()
carcinogenic_molecules = molecule[molecule["label"] == "+"].shape[0]
result = round((carcinogenic_molecules / total_molecules) * 100, 3)


SELECT ROUND(CAST((CAST(COUNT(CASE WHEN T.element = 'h' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0)) AS NUMERIC), 4) AS percentage FROM atom AS T WHERE T.molecule_id = 'TR206'

filtered_df = atom[atom["molecule_id"] == "TR206"]
hydrogen_count = filtered_df[filtered_df["element"] == "h"]["atom_id"].count()
total_count = filtered_df["atom_id"].count()
result = round((hydrogen_count / total_count) * 100, 4)


SELECT DISTINCT T1.element, T2.label FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.molecule_id = 'TR060'

merged_df = pd.merge(atom, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[merged_df["molecule_id"] == "TR060"]
result = filtered_df[["element", "label"]].drop_duplicates()


SELECT T.bond_type FROM (SELECT T1.bond_type, COUNT(T1.molecule_id) FROM bond AS T1 WHERE T1.molecule_id = 'TR010' GROUP BY T1.bond_type ORDER BY COUNT(T1.molecule_id) DESC NULLS LAST LIMIT 1) AS T

filtered_bonds = bond[bond["molecule_id"] == "TR010"]
bond_type_counts = filtered_bonds["bond_type"].value_counts()
result = bond_type_counts.idxmax()


SELECT DISTINCT T2.molecule_id FROM bond AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.bond_type = '-' AND T2.label = '-' ORDER BY T2.molecule_id NULLS FIRST LIMIT 3

merged_df = pd.merge(bond, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[(merged_df["bond_type"] == "-") & (merged_df["label"] == "-")]
result = filtered_df["molecule_id"].drop_duplicates().sort_values().head(3).tolist()


SELECT T1.bond_type, T2.atom_id, T2.atom_id2 FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id WHERE T2.bond_id = 'TR001_6_9'

merged_df = pd.merge(bond, connected, left_on="bond_id", right_on="bond_id", how="inner")
filtered_df = merged_df[merged_df["bond_id"] == "TR001_6_9"]
result = filtered_df[["bond_type", "atom_id", "atom_id2"]]


SELECT COUNT(T.bond_id) FROM connected AS T WHERE RIGHT(T.atom_id, 2) = '19'

filtered_df = connected[connected["atom_id"].str.endswith("19")]
result = filtered_df["bond_id"].count()


SELECT T2.bond_id FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id WHERE T2.bond_id IN (SELECT T3.bond_id FROM connected AS T3 INNER JOIN atom AS T4 ON T3.atom_id = T4.atom_id WHERE T4.element = 'p') AND T1.element = 'n'

connected_with_p = connected[connected["atom_id"].isin(atom[atom["element"] == "p"]["atom_id"])]
bonds_with_p = connected_with_p["bond_id"].unique()
connected_with_n = connected[connected["bond_id"].isin(bonds_with_p) & connected["atom_id"].isin(atom[atom["element"] == "n"]["atom_id"])]
result = connected_with_n["bond_id"].unique()


SELECT T1.label FROM molecule AS T1 INNER JOIN (SELECT T.molecule_id, COUNT(T.bond_type) FROM bond AS T WHERE T.bond_type = '=' GROUP BY T.molecule_id ORDER BY COUNT(T.bond_type) DESC NULLS LAST LIMIT 1) AS T2 ON T1.molecule_id = T2.molecule_id

double_bonds_count = bond[bond["bond_type"] == "="].groupby("molecule_id").size().reset_index(name="count")
max_double_bond_molecule = double_bonds_count.sort_values(by="count", ascending=False).head(1)
result = molecule[molecule["molecule_id"].isin(max_double_bond_molecule["molecule_id"])]["label"].iloc[0]


SELECT DISTINCT T.element FROM atom AS T WHERE NOT T.atom_id IN (SELECT DISTINCT atom_id FROM connected)

bonded_atoms = connected["atom_id"].unique()
unbonded_atoms = atom[~atom["atom_id"].isin(bonded_atoms)]
result = unbonded_atoms["element"].unique()


SELECT T2.atom_id, T2.atom_id2 FROM atom AS T1 INNER JOIN connected AS T2 ON T1.atom_id = T2.atom_id INNER JOIN bond AS T3 ON T2.bond_id = T3.bond_id WHERE T3.bond_type = '#' AND T3.molecule_id = 'TR041'

merged_df1 = pd.merge(atom, connected, left_on="atom_id", right_on="atom_id", how="inner")
merged_df2 = pd.merge(merged_df1, bond, left_on="bond_id", right_on="bond_id", how="inner")
filtered_df = merged_df2[(merged_df2["bond_type"] == "#")& (merged_df2["molecule_id_y"] == "TR041")]
result = filtered_df[["atom_id", "atom_id2"]]


SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR144_8_19'

merged_df = pd.merge(connected, atom, left_on="atom_id", right_on="atom_id", how="inner")
filtered_df = merged_df[merged_df["bond_id"] == "TR144_8_19"]
result = filtered_df["element"]


SELECT DISTINCT T3.element FROM bond AS T1 INNER JOIN connected AS T2 ON T1.bond_id = T2.bond_id INNER JOIN atom AS T3 ON T2.atom_id = T3.atom_id WHERE T1.bond_type = '#'

merged_df1 = pd.merge(bond, connected, left_on="bond_id", right_on="bond_id", how="inner")
merged_df2 = pd.merge(merged_df1, atom, left_on="atom_id", right_on="atom_id", how="inner")
filtered_df = merged_df2[merged_df2["bond_type"] == "#"]
result = filtered_df["element"].drop_duplicates()


SELECT CAST(COUNT(CASE WHEN T.element = 'cl' THEN T.atom_id ELSE NULL END) AS REAL) * 100 / NULLIF(COUNT(T.atom_id), 0) FROM atom AS T WHERE molecule_id IN (SELECT DISTINCT molecule.molecule_id FROM molecule JOIN bond ON molecule.molecule_id = bond.molecule_id AND bond.bond_type = '-')

single_bond_molecules = bond[bond["bond_type"] == "-"]["molecule_id"].unique()
filtered_atoms = atom[atom["molecule_id"].isin(single_bond_molecules)]
cl_count = filtered_atoms[filtered_atoms["element"] == "cl"]["atom_id"].count()
total_count = filtered_atoms["atom_id"].count()
result = (cl_count / total_count) * 100


SELECT T2.element FROM connected AS T1 INNER JOIN atom AS T2 ON T1.atom_id = T2.atom_id WHERE T1.bond_id = 'TR001_10_11'

merged_df = pd.merge(connected, atom, left_on="atom_id", right_on="atom_id", how="inner")
filtered_df = merged_df[merged_df["bond_id"] == "TR001_10_11"]
result = filtered_df["element"]


SELECT DISTINCT T1.element FROM atom AS T1 INNER JOIN molecule AS T2 ON T1.molecule_id = T2.molecule_id WHERE T2.label = '+' AND RIGHT(T1.atom_id, 1) = '4' AND LENGTH(T1.atom_id) = 7

merged_df = pd.merge(atom, molecule, left_on="molecule_id", right_on="molecule_id", how="inner")
filtered_df = merged_df[(merged_df["label"] == "+") & (merged_df["atom_id"].str[-1] == "4") & (merged_df["atom_id"].str.len() == 7)]
result = filtered_df["element"].unique()


SELECT T.molecule_id FROM (SELECT T1.molecule_id, COUNT(T2.atom_id) FROM molecule AS T1 INNER JOIN atom AS T2 ON T1.molecule_id = T2.molecule_id WHERE T1.label = '-' GROUP BY T1.molecule_id HAVING COUNT(T2.atom_id) > 5) AS t

merged_df = pd.merge(molecule, atom, on="molecule_id", how="inner")
filtered_df = merged_df[merged_df["label"] == "-"]
grouped_df = filtered_df.groupby("molecule_id").size().reset_index(name='atom_count')
result = grouped_df[grouped_df["atom_count"] > 5]["molecule_id"]


SELECT T2.CDSCode FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2."Enrollment (K-12)" + T2."Enrollment (Ages 5-17)" > 500

merged_df = pd.merge(schools, frpm, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["Enrollment (K-12)"] + merged_df["Enrollment (Ages 5-17)"]) > 500]
result = filtered_df["CDSCode"]


SELECT MAX(CAST(T1."Free Meal Count (Ages 5-17)" AS REAL) / NULLIF(T1."Enrollment (Ages 5-17)", 0)) FROM frpm AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE CAST(T2.NumGE1500 AS REAL) / NULLIF(T2.NumTstTakr, 0) > 0.3

merged_df = pd.merge(frpm, satscores, left_on="CDSCode", right_on="cds", how="inner")
filtered_df = merged_df[(merged_df["NumGE1500"] / merged_df["NumTstTakr"]) > 0.3]
result = (filtered_df["Free Meal Count (Ages 5-17)"] / filtered_df["Enrollment (Ages 5-17)"]).max()


SELECT CharterNum, AvgScrWrite, RANK() OVER (ORDER BY AvgScrWrite DESC NULLS LAST) AS WritingScoreRank FROM schools AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T2.AvgScrWrite > 499 AND NOT CharterNum IS NULL

merged_df = pd.merge(schools, satscores, left_on="CDSCode", right_on="cds", how="inner")
filtered_df = merged_df[(merged_df["AvgScrWrite"] > 499) & (merged_df["CharterNum"].notnull())]
filtered_df["WritingScoreRank"] = filtered_df["AvgScrWrite"].rank(method="min", ascending=False)
result = filtered_df[["CharterNum", "AvgScrWrite", "WritingScoreRank"]]


SELECT T1.School, T1.Street FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2."Enrollment (K-12)" - T2."Enrollment (Ages 5-17)" > 30

merged_df = pd.merge(schools, frpm, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["Enrollment (K-12)"] - merged_df["Enrollment (Ages 5-17)"]) > 30]
result = filtered_df[["School", "Street"]]


SELECT T2."School Name" FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE CAST(T2."Free Meal Count (K-12)" AS REAL) / NULLIF(T2."Enrollment (K-12)", 0) > 0.1 AND T1.NumGE1500 > 0

merged_df = pd.merge(satscores, frpm, left_on="cds", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["Free Meal Count (K-12)"] / merged_df["Enrollment (K-12)"] > 0.1) & (merged_df["NumGE1500"] > 0)]
result = filtered_df["School Name"]


SELECT T1."School Name", T2.Street, T2.City, T2.State, T2.Zip FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Monterey' AND T1."FRPM Count (Ages 5-17)" > 800 AND T1."School Type" = 'High Schools (Public)'

merged_df = pd.merge(frpm, schools, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[
(merged_df["County"] == "Monterey") &
(merged_df["FRPM Count (Ages 5-17)"] > 800) &
(merged_df["School Type"] == "High Schools (Public)")
]
result = filtered_df[["School Name", "Street", "City", "State", "Zip"]]


SELECT T2.School, T2.DOCType FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.FundingType = 'Locally funded' AND (T1."Enrollment (K-12)" - T1."Enrollment (Ages 5-17)") > (SELECT AVG(T3."Enrollment (K-12)" - T3."Enrollment (Ages 5-17)") FROM frpm AS T3 INNER JOIN schools AS T4 ON T3.CDSCode = T4.CDSCode WHERE T4.FundingType = 'Locally funded')

merged_df = pd.merge(frpm, schools, left_on="CDSCode", right_on="CDSCode", how="inner")
locally_funded_df = merged_df[merged_df["FundingType"] == "Locally funded"]
locally_funded_df["Enrollment_Difference"] = locally_funded_df["Enrollment (K-12)"] - locally_funded_df["Enrollment (Ages 5-17)"]
average_difference = locally_funded_df["Enrollment_Difference"].mean()
result = locally_funded_df[locally_funded_df["Enrollment_Difference"] > average_difference][["School", "DOCType"]]


SELECT CAST(T1."FRPM Count (K-12)" AS REAL) / NULLIF(T1."Enrollment (K-12)", 0) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.SOC::integer = 66 ORDER BY T1."FRPM Count (K-12)" DESC NULLS LAST LIMIT 5

merged_df = pd.merge(frpm, schools, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[merged_df["SOC"] == "66"]
filtered_df["Eligible Rate"] = filtered_df["FRPM Count (K-12)"] / filtered_df["Enrollment (K-12)"]
sorted_df = filtered_df.sort_values(by="FRPM Count (K-12)", ascending=False)
result = sorted_df.head(5)["Eligible Rate"]


SELECT AVG(T1.NumTstTakr) FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE TO_CHAR(CAST(T2.OpenDate AS TIMESTAMP), 'YYYY') = '1980' AND T2.County = 'Fresno'

schools['OpenDate'] = pd.to_datetime(schools['OpenDate'], errors='coerce')

merged_df = pd.merge(satscores, schools, left_on="cds", right_on="CDSCode", how="inner")

filtered_df = merged_df[(merged_df["OpenDate"].dt.year == 1980) & (merged_df["County"] == "Fresno")]

result = filtered_df["NumTstTakr"].mean()


SELECT T2.Phone FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.District = 'Fresno Unified' AND NOT T1.AvgScrRead IS NULL ORDER BY T1.AvgScrRead ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(satscores, schools, left_on="cds", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["District"] == "Fresno Unified") & (merged_df["AvgScrRead"].notnull())]
sorted_df = filtered_df.sort_values(by="AvgScrRead", ascending=True)
result = sorted_df.iloc[0]["Phone"]


SELECT T2.School, T1.AvgScrWrite FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode WHERE T2.AdmFName1 = 'Ricci' AND T2.AdmLName1 = 'Ulrich'

merged_df = pd.merge(satscores, schools, left_on="cds", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["AdmFName1"] == "Ricci") & (merged_df["AdmLName1"] == "Ulrich")]
result = filtered_df[["School", "AvgScrWrite"]]


SELECT T2.School FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.DOC = '31' ORDER BY T1."Enrollment (K-12)" DESC LIMIT 1

merged_df = pd.merge(frpm, schools, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[merged_df["DOC"] == "31"]
sorted_df = filtered_df.sort_values(by="Enrollment (K-12)", ascending=False)
if not sorted_df.empty:
    result = sorted_df.iloc[0]["School"]
else:
    result = None


SELECT CAST(COUNT(School) AS REAL) / NULLIF(12, 0) FROM schools WHERE DOC = '52' AND County = 'Alameda' AND EXTRACT(YEAR FROM OpenDate) = 1980

filtered_df = schools[(schools["DOC"] == "52") & (schools["County"] == "Alameda") & (schools["OpenDate"].str[:4] == "1980")]
result = filtered_df["School"].count() / 12


SELECT CAST(SUM(CASE WHEN DOC::integer = 54 THEN 1 ELSE 0 END) AS REAL) / NULLIF(SUM(CASE WHEN DOC::integer = 52 THEN 1 ELSE 0 END), 0) FROM schools WHERE StatusType = 'Merged' AND County = 'Orange'

filtered_df = schools[(schools["StatusType"] == "Merged") & (schools["County"] == "Orange")]
unified_count = (filtered_df["DOC"] == "54").sum()
elementary_count = (filtered_df["DOC"] == "52").sum()
result = unified_count / elementary_count


SELECT T2.MailStreet, T2.School FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.AvgScrMath DESC NULLS LAST LIMIT 1 OFFSET 6

merged_df = pd.merge(satscores, schools, left_on="cds", right_on="CDSCode", how="inner")
sorted_df = merged_df.sort_values(by="AvgScrMath", ascending=False)
seventh_highest = sorted_df.iloc[6]
result = (seventh_highest["MailStreet"], seventh_highest["School"])


SELECT County, COUNT(Virtual) FROM schools WHERE (County = 'San Diego' OR County = 'Santa Barbara') AND Virtual = 'F' GROUP BY County ORDER BY COUNT(Virtual) DESC NULLS LAST LIMIT 1

filtered_df = schools[(schools["County"].isin(["San Diego", "Santa Barbara"])) & (schools["Virtual"] == "F")]
grouped_df = filtered_df.groupby("County").size().reset_index(name='count')
result = grouped_df.nlargest(1, 'count')


SELECT GSoffered FROM schools ORDER BY ABS(longitude) DESC NULLS LAST LIMIT 1

result = schools.loc[schools['Longitude'].abs().idxmax(), 'GSoffered']


SELECT T2.City, COUNT(T2.CDSCode) FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.Magnet = 1 AND T2.GSoffered = 'K-8' AND T1."NSLP Provision Status" = 'Multiple Provision Types' GROUP BY T2.City

merged_df = pd.merge(frpm, schools, left_on="CDSCode", right_on="CDSCode", how="inner")
filtered_df = merged_df[(merged_df["Magnet"] == 1) & (merged_df["GSoffered"] == "K-8") & (merged_df["NSLP Provision Status"] == "Multiple Provision Types")]
result = filtered_df.groupby("City")["CDSCode"].count().reset_index()


SELECT T2.AdmEmail1, T2.AdmEmail2 FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'San Bernardino' AND T2.City = 'San Bernardino' AND T2.DOC::integer = 54 AND EXTRACT(YEAR FROM T2.OpenDate) BETWEEN 2009 AND 2010 AND T2.SOC::integer = 62

merged_df = pd.merge(frpm, schools, on="CDSCode", how="inner")
filtered_df = merged_df[
(merged_df["County"] == "San Bernardino") &
(merged_df["City"] == "San Bernardino") &
(merged_df["DOC"].astype(str) == "54") &
(merged_df["SOC"].astype(str) == "62") &
(merged_df["OpenDate"].between("2009-01-01", "2010-12-31"))
]
result = filtered_df[["AdmEmail1", "AdmEmail2"]]


SELECT COUNT(T2.account_id) FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id WHERE T1.A3 = 'east Bohemia' AND T2.frequency = 'POPLATEK PO OBRATU'

merged_df = pd.merge(district, account, left_on="district_id", right_on="district_id", how="inner")
filtered_df = merged_df[(merged_df["A3"] == "east Bohemia") & (merged_df["frequency"] == "POPLATEK PO OBRATU")]
result = filtered_df["account_id"].count()


SELECT COUNT(DISTINCT T2.district_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'F' AND T2.A11 BETWEEN 6000 AND 10000

merged_df = pd.merge(client, district, left_on="district_id", right_on="district_id", how="inner")
filtered_df = merged_df[(merged_df["gender"] == "F") & (merged_df["A11"] > 6000) & (merged_df["A11"] < 10000)]
result = filtered_df["district_id"].nunique()


SELECT T1.account_id, (SELECT MAX(A11) - MIN(A11) FROM district) FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T1.account_id = T3.account_id INNER JOIN client AS T4 ON T3.client_id = T4.client_id WHERE T2.district_id = (SELECT district_id FROM client WHERE gender = 'F' ORDER BY birth_date ASC NULLS FIRST LIMIT 1) ORDER BY T2.A11 DESC NULLS LAST LIMIT 1

oldest_female_district_id = client[client["gender"] == "F"].sort_values("birth_date").iloc[0]["district_id"]

district_gap = district["A11"].max() - district["A11"].min()

merged_df = account.merge(district, on="district_id").merge(disp, on="account_id").merge(client, on="client_id")

filtered_df = merged_df[(merged_df["district_id_x"] == oldest_female_district_id)]

result = filtered_df.sort_values("A11", ascending=False).iloc[0][["account_id"]].to_frame().assign(gap=district_gap)


SELECT T1.account_id FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id WHERE TO_CHAR(CAST(T2.date AS TIMESTAMP), 'YYYY') = '1993' AND T1.duration > 12 ORDER BY T1.amount DESC NULLS LAST LIMIT 1

account['date'] = pd.to_datetime(account['date'])
loan['date'] = pd.to_datetime(loan['date'])

merged_df = pd.merge(loan, account, left_on="account_id", right_on="account_id", how="inner")

filtered_df = merged_df[(merged_df["duration"] > 12) & (merged_df["date_y"].dt.year == 1993)]

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

result = sorted_df.iloc[0]["account_id"]


SELECT COUNT(T2.client_id) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T2.gender = 'F' AND TO_CHAR(CAST(T2.birth_date AS TIMESTAMP), 'YYYY') < '1950' AND T1.A2 = 'Sokolov'

merged_df = pd.merge(district, client, left_on="district_id", right_on="district_id", how="inner")
filtered_df = merged_df[(merged_df["gender"] == "F") & (merged_df["birth_date"] < '1950-01-01') & (merged_df["A2"] == "Sokolov")]
result = filtered_df["client_id"].count()


SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T1.client_id), 0) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'south Bohemia' GROUP BY T2.A4 ORDER BY CAST(T2.A4 AS INT) DESC LIMIT 1

merged_df = pd.merge(client, district, left_on="district_id", right_on="district_id", how="inner")
south_bohemia_df = merged_df[merged_df["A3"] == "south Bohemia"]
grouped_df = south_bohemia_df.groupby("A4").agg(
male_clients=("gender", lambda x: (x == 'M').sum()),
total_clients=("client_id", "count")
).reset_index()
grouped_df["percentage_male"] = (grouped_df["male_clients"] * 100) / grouped_df["total_clients"]
sorted_df = grouped_df.sort_values(by="A4", key=lambda x: x.astype(int), ascending=False)
result = sorted_df["percentage_male"].iloc[0]


SELECT CAST((SUM(CASE WHEN T3.date = '1998-12-27' THEN T3.balance ELSE 0 END) - SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END)) AS REAL) * 100 / NULLIF(SUM(CASE WHEN T3.date = '1993-03-22' THEN T3.balance ELSE 0 END), 0) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN trans AS T3 ON T3.account_id = T2.account_id WHERE T1.date = '1993-07-05'

loan_account = loan[loan["date"] == "1993-07-05"].iloc[0]["account_id"]
trans_filtered = trans[trans["account_id"] == loan_account]
balance_1998_12_27 = trans_filtered[trans_filtered["date"] == "1998-12-27"]["balance"].sum()
balance_1993_03_22 = trans_filtered[trans_filtered["date"] == "1993-03-22"]["balance"].sum()
result = ((balance_1998_12_27 - balance_1993_03_22) / balance_1993_03_22) * 100


SELECT (CAST(SUM(CASE WHEN status = 'A' THEN amount ELSE 0 END) AS REAL) * 100) / NULLIF(SUM(amount), 0) FROM loan

total_amount = loan["amount"].sum()
amount_no_issue = loan.loc[loan["status"] == "A", "amount"].sum()
result = (amount_no_issue * 100) / total_amount


SELECT CAST(SUM(CASE WHEN status = 'C' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(account_id), 0) FROM loan WHERE amount < 100000

filtered_loan = loan[loan["amount"] < 100000]
running_accounts = filtered_loan["status"].eq('C').sum()
total_accounts = filtered_loan["account_id"].count()
result = (running_accounts * 100.0) / total_accounts


SELECT COUNT(T1.client_id) FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T1.gender = 'M' AND T2.A15 = (SELECT T3.A15 FROM district AS T3 ORDER BY T3.A15 DESC NULLS LAST LIMIT 1 OFFSET 1)

second_highest_crimes = district["A15"].nlargest(2).iloc[-1]
merged_df = pd.merge(client, district, left_on="district_id", right_on="district_id", how="inner")
filtered_df = merged_df[(merged_df["gender"] == "M") & (merged_df["A15"] == second_highest_crimes)]
result = filtered_df["client_id"].count()


SELECT T2.account_id FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T2.account_id = T3.account_id WHERE T3.type = 'OWNER' AND T1.A2 = 'Tabor'

merged_df1 = pd.merge(district, account, left_on="district_id", right_on="district_id", how="inner")
merged_df2 = pd.merge(merged_df1, disp, left_on="account_id", right_on="account_id", how="inner")
filtered_df = merged_df2[(merged_df2["type"] == "OWNER") & (merged_df2["A2"] == "Tabor")]
result = filtered_df["account_id"]


SELECT T3.type FROM district AS T1 INNER JOIN account AS T2 ON T1.district_id = T2.district_id INNER JOIN disp AS T3 ON T2.account_id = T3.account_id WHERE T3.type <> 'OWNER' AND T1.A11 BETWEEN 8000 AND 9000

merged_df1 = pd.merge(district, account, left_on="district_id", right_on="district_id", how="inner")
merged_df2 = pd.merge(merged_df1, disp, left_on="account_id", right_on="account_id", how="inner")
filtered_df = merged_df2[(merged_df2["type"] != "OWNER") & (merged_df2["A11"].between(8000, 9000))]
result = filtered_df["type"]


SELECT CAST(SUM(CASE WHEN T2.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / NULLIF(COUNT(T2.client_id), 0) FROM district AS T1 INNER JOIN client AS T2 ON T1.district_id = T2.district_id WHERE T1.A11 > 10000

merged_df = pd.merge(district, client, left_on="district_id", right_on="district_id", how="inner")
filtered_df = merged_df[merged_df["A11"] > 10000]
percentage_women = (filtered_df["gender"] == 'F').sum() * 100 / filtered_df["client_id"].count()
result = percentage_women


SELECT T3.account_id FROM client AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id INNER JOIN account AS T3 ON T2.district_id = T3.district_id INNER JOIN disp AS T4 ON T1.client_id = T4.client_id AND T4.account_id = T3.account_id WHERE T1.gender = 'F' ORDER BY T1.birth_date ASC NULLS FIRST, T2.A11 ASC NULLS FIRST LIMIT 1

merged_df = pd.merge(client, district, left_on="district_id", right_on="district_id", how="inner")
merged_df = pd.merge(merged_df, account, left_on="district_id", right_on="district_id", how="inner")
merged_df = pd.merge(merged_df, disp, left_on=["client_id", "account_id"], right_on=["client_id", "account_id"], how="inner")
filtered_df = merged_df[merged_df["gender"] == "F"]
sorted_df = filtered_df.sort_values(by=["birth_date", "A11"], ascending=[True, True])
result = sorted_df.iloc[0]["account_id"]


SELECT AVG(T2.amount) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.status IN ('C', 'D') AND T1.frequency = 'POPLATEK PO OBRATU'

merged_df = pd.merge(account, loan, left_on="account_id", right_on="account_id", how="inner")
filtered_df = merged_df[(merged_df["status"].isin(['C', 'D'])) & (merged_df["frequency"] == 'POPLATEK PO OBRATU')]
result = filtered_df["amount"].mean()


SELECT T1.client_id, EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM T3.birth_date) AS age FROM disp AS T1 INNER JOIN card AS T2 ON T2.disp_id = T1.disp_id INNER JOIN client AS T3 ON T1.client_id = T3.client_id WHERE T2.type = 'gold' AND T1.type = 'OWNER'

from datetime import datetime

current_year = datetime.now().year
merged_df = pd.merge(disp, card, on="disp_id", how="inner")
merged_df = pd.merge(merged_df, client, on="client_id", how="inner")
filtered_df = merged_df[(merged_df["type_x"] == "OWNER") & (merged_df["type_y"] == "gold")]
filtered_df["age"] = current_year - pd.to_datetime(filtered_df["birth_date"]).dt.year
result = filtered_df[["client_id", "age"]]