<jupyter_start><jupyter_text>Problem StatementWrite an efficient SQL query (in this case I am using Python and Pandas, and later in the future I plan to learn more about SQL) to calculate the total revenues made in the months of September and October. They need to be broken down by channnel.<jupyter_code># A: init a dict to keep track of the revenue made for each channel

channels = orders['channel'].unique()
channel_revenue = dict(
    zip(channels,
        [0 for i in range(len(channels))]
    )
)
# B: iterate over the rows of the orders df
months = [9, 10]

# select the rows that fall in Sept. and Oct
query_orders = orders.loc[(orders['month'] == 'September') | (orders['month'] == 'October'), ['order_id','channel']]
query_orders
# iterate over queried orders
for order_id, channel in zip(query_orders['order_id'], query_orders['channel']):
    # get the row containing the revenue associated with order
    revenue = order_revenues.loc[order_revenues['order_id'] == order_id, ['revenue']]
    # get the acutal revenue amount
    revenue = int(revenue['revenue'])
    # add it to the revenues, for the appropiate channel
    channel_revenue[channel] += revenue
# show the resulting channel revenues for Sept. and Oct.
channel_revenue
plt.bar(list(channel_revenue.keys()), list(channel_revenue.values()))
plt.title('Revenue by Channel, Sept - October 2018')
plt.xlabel('Channel')
plt.ylabel('Revenue (USD)')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11034955448937629, 'fraction_numerical': 0.0054832076764907475, 'mean_word_length': 5.033057851239669, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '26557', 'license': 'MIT', 'n_tokens_mistral': 451, 'n_tokens_neox': 429, 'n_words': 163, 'path': 'revenue_problem.ipynb', 'repo_name': 'UPstartDeveloper/fictional-barnacle', 'size': '1459'}