<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emmanuel Udoh</title>
    <description>The latest articles on DEV Community by Emmanuel Udoh (@eudoh940).</description>
    <link>https://dev.to/eudoh940</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F163852%2F38919b07-cfee-4cf6-990e-7d391d7dab9a.jpg</url>
      <title>DEV Community: Emmanuel Udoh</title>
      <link>https://dev.to/eudoh940</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eudoh940"/>
    <language>en</language>
    <item>
      <title>Sort one column by another column in powerBI</title>
      <dc:creator>Emmanuel Udoh</dc:creator>
      <pubDate>Fri, 26 Apr 2024 02:49:35 +0000</pubDate>
      <link>https://dev.to/eudoh940/sort-one-column-by-another-column-in-powerbi-d5f</link>
      <guid>https://dev.to/eudoh940/sort-one-column-by-another-column-in-powerbi-d5f</guid>
      <description>&lt;p&gt;When you are given a task to complete and you find out that you need to sort a column by another column, for example, sorting the month name by the month number, this is what to do.&lt;/p&gt;

&lt;p&gt;After you have added the month name to a visual, sometimes, it will be in alphabetical order; April, August, December and so on as shown in the picture below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7cx5urts5clok8xy5d3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx7cx5urts5clok8xy5d3.PNG" alt="Image description" width="427" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, it might not be in alphabetical order. Don't panic. Just read on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set the column to use for sorting
&lt;/h2&gt;

&lt;p&gt;To sort a column, you need a column with a number for each month in order to properly carry out the task. Any graphic in the report that has a sorted column will follow the order specified in the sorting. The months in the sample below are arranged alphabetically, but they ought to be arranged chronologically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flptbf59xslpv8ktx3ot6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flptbf59xslpv8ktx3ot6.PNG" alt="Image description" width="427" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to carry out this task:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Select the column that you want to sort, in this case, month name. Note that the months in the graph are sorted alphabetically. In the Fields pane, the Column Tools tab becomes active.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pqyjf4p7nx6y5irxx6h.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pqyjf4p7nx6y5irxx6h.PNG" alt="Image description" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select Sort by Column, then select the field you want to sort the other field by, which is, Month Number in this case.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgx0ihjp2zr9lafhfvyg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgx0ihjp2zr9lafhfvyg.PNG" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The graph automatically sorts chronologically by the number of months in a year.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqlz1xp2sxqkspd7jb6pm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqlz1xp2sxqkspd7jb6pm.PNG" alt="Image description" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>learning</category>
      <category>writing</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>How to connect ChatGPT to a SQL database for data retrieval and analysis</title>
      <dc:creator>Emmanuel Udoh</dc:creator>
      <pubDate>Sat, 23 Mar 2024 02:31:46 +0000</pubDate>
      <link>https://dev.to/eudoh940/how-to-connect-chatgpt-to-a-sql-database-for-data-retrieval-and-analysis-2k4h</link>
      <guid>https://dev.to/eudoh940/how-to-connect-chatgpt-to-a-sql-database-for-data-retrieval-and-analysis-2k4h</guid>
      <description>&lt;ul&gt;
&lt;li&gt;What is chatGPT?&lt;/li&gt;
&lt;li&gt;How chatGPT works&lt;/li&gt;
&lt;li&gt;How to use ChatGPT in Data Analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is chatGPT?
&lt;/h2&gt;

&lt;p&gt;ChatGPT is an advanced language model that can be used to generate tasks. It can also be used to understand tasks. ChatGPT can be used to write contents, emails, and articles, even to the extent of writing and explaining codes. ChatGPT can be used to generate data, unit codes, and train machine learning modules.&lt;/p&gt;

&lt;h2&gt;
  
  
  How chatGPT works
&lt;/h2&gt;

&lt;p&gt;To be able to work with chatGPT, head over to &lt;a href="https://chat.openai.com/"&gt;ChatGPT&lt;/a&gt; and sign up if you haven't already. If you have signed up, all you need to do is log in&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eafnib70lrxehir3pog.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9eafnib70lrxehir3pog.PNG" alt="Image description" width="800" height="358"&gt;&lt;/a&gt;&lt;br&gt;
Once you click on Sign Up or Log in, it brings you the sign-up or log-in page where you will have to sign in with your Email, Apple or Microsoft account &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7a00esd5z1nofm94emn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7a00esd5z1nofm94emn.PNG" alt="Image description" width="471" height="538"&gt;&lt;/a&gt;&lt;br&gt;
After sign-in, you will get to see the next page where you have to input your prompt and start getting responses from ChatGPT&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48elimzomy35awc2h2dw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48elimzomy35awc2h2dw.PNG" alt="Image description" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One thing to know is that once you prompt chatGPT, it can always refer back to the question you asked it previously, provided you are still on the same page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpkk4f7ghxzp0s7amz42.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpkk4f7ghxzp0s7amz42.PNG" alt="Image description" width="784" height="514"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  ChatGPT for Data Analysis
&lt;/h2&gt;

&lt;p&gt;Now let's use ChatGPT for data analysis. &lt;br&gt;
First, we will go to &lt;a href="https://www.w3schools.com/sql"&gt;w3schools&lt;/a&gt; to get data sets. Click on the try it yourself button. it will bring you to the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgo9re8secttvuk3lan09.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgo9re8secttvuk3lan09.PNG" alt="Image description" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the customers to products, then click on the "Run SQL" button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsu6tif4egxyovthg5v5t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsu6tif4egxyovthg5v5t.PNG" alt="Image description" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy some entries from the table, including the headers, &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpo827n27qigon21eo6j.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpo827n27qigon21eo6j.PNG" alt="Image description" width="800" height="318"&gt;&lt;/a&gt;&lt;br&gt;
Go to chatGPT and paste them. &lt;br&gt;
Instruct it that this is the product table. It is going to bring out the results of the interpretation of the table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqed9g3gtzwa76isunar.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsqed9g3gtzwa76isunar.PNG" alt="Image description" width="787" height="506"&gt;&lt;/a&gt;&lt;br&gt;
From here, we can ask it any question of our choice. &lt;br&gt;
First, let's ask about the product with the highest price.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffj0bj8oa9w5391k3ptcq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffj0bj8oa9w5391k3ptcq.PNG" alt="Image description" width="800" height="314"&gt;&lt;/a&gt;&lt;br&gt;
If you go over to the table, you will find out that the highest price is 40 for Northwood Cranberry Sauce. Indeed, it is correct.&lt;/p&gt;

&lt;p&gt;Ask for the lowest price. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxjc1ow19pq4xcj2hpvsp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxjc1ow19pq4xcj2hpvsp.PNG" alt="Image description" width="737" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also prompt ChatGPT for the average of the products. It will not only give you the average, it will also show you how to calculate it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzpmj2jdo1ffm0xulx4g.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzpmj2jdo1ffm0xulx4g.PNG" alt="Image description" width="613" height="283"&gt;&lt;/a&gt;&lt;br&gt;
Lets go ahead and solve this using SQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG(Price) AS AveragePrice FROM products;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let prompt chatGPT write the SQL query for the product with the highest price &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91uzgj842smyb92o9h5b.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91uzgj842smyb92o9h5b.PNG" alt="Image description" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Prompt ChatGPT to get the product with the lowest price&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2i6hkkltzqsqu2c7n0ui.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2i6hkkltzqsqu2c7n0ui.PNG" alt="Image description" width="798" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Tell it to calculate the average&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wphr79rol2sywdqi421.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2wphr79rol2sywdqi421.PNG" alt="Image description" width="800" height="408"&gt;&lt;/a&gt;&lt;br&gt;
Now it's time to make things a little bit harder. So we have to make ChatGPT join two tables together. So go back to &lt;a href="https://www.w3schools.com/sql"&gt;w3schools&lt;/a&gt; to get the OrderDetails table&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcoa5mdlszphtio3rg27.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdcoa5mdlszphtio3rg27.PNG" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then copy the values you get there and paste them in ChatGPT. You will get something like this below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29t6smy3rzdqcwklofo1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29t6smy3rzdqcwklofo1.PNG" alt="Image description" width="796" height="383"&gt;&lt;/a&gt;&lt;br&gt;
Also, do same for orders table and then suppliers table&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59esjy8y1y4j1nha6suw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59esjy8y1y4j1nha6suw.PNG" alt="Image description" width="773" height="391"&gt;&lt;/a&gt;&lt;br&gt;
Finally, you do the suppliers table&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftrwwnujc6lzwx7q3z58.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftrwwnujc6lzwx7q3z58.PNG" alt="Image description" width="800" height="406"&gt;&lt;/a&gt;&lt;br&gt;
Continue by asking ChatGPT to write SQL query to calculate the averageproduct price per supplier. The code below is useful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT s.SupplierName, AVG(p.Price) AS AvgPrice
FROM Suppliers s
JOIN Products p ON s.SupplierID = p.SupplierID
GROUP BY s.SupplierName
ORDER BY AvgPrice DESC;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that the query above first joins the “Suppliers” and “Products” tables on the SupplierID field. It then groups the results by SupplierName and calculates the average price for each group. &lt;/p&gt;

&lt;p&gt;Finally, it orders the results by AvgPrice in descending order. &lt;/p&gt;

&lt;p&gt;Replace the table and column names if they are different in your database.&lt;/p&gt;

&lt;p&gt;Next, write an SQL query that gets the products that achieved the highest revenue&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT p.ProductName, SUM(od.Quantity * p.Price) AS Revenue
FROM Products p
JOIN OrderDetails od ON p.ProductID = od.ProductID
GROUP BY p.ProductName
ORDER BY Revenue DESC;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query first joins the “Products” and “OrderDetails” tables on the ProductID field. It then groups the results by ProductName and calculates the total revenue for each product (which is the sum of the product of Quantity and Price for each order detail). &lt;/p&gt;

&lt;p&gt;Finally, it orders the results by Revenue in descending order. &lt;/p&gt;

&lt;p&gt;Replace the table and column names if they are different in your database. If you want to limit the result to the top product, you can add a LIMIT 1 clause at the end of the query.&lt;/p&gt;

&lt;p&gt;Next, ChatGPT is going to write an SQL query that gets the employee that made the highest sales from the table above&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT e.EmployeeID, SUM(od.Quantity * p.Price) AS Sales
FROM Employees e
JOIN Orders o ON e.EmployeeID = o.EmployeeID
JOIN OrderDetails od ON o.OrderID = od.OrderID
JOIN Products p ON od.ProductID = p.ProductID
GROUP BY e.EmployeeID
ORDER BY Sales DESC
LIMIT 1;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can prompt ChatGPT to use window functions and subqueries by asking it about employees that made the second highest sales. Check out the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT EmployeeID, Sales
FROM (
    SELECT e.EmployeeID, SUM(od.Quantity * p.Price) AS Sales,
    DENSE_RANK() OVER (ORDER BY SUM(od.Quantity * p.Price) DESC) as SalesRank
    FROM Employees e
    JOIN Orders o ON e.EmployeeID = o.EmployeeID
    JOIN OrderDetails od ON o.OrderID = od.OrderID
    JOIN Products p ON od.ProductID = p.ProductID
    GROUP BY e.EmployeeID
) AS EmployeeSales
WHERE SalesRank = 2;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;first of all, Sure, to find the employee that made the second highest sales, you can use a subquery to rank employees by sales and then select the one with the second highest sales. Here is an SQL query that gets the employee that achieved the second highest sales:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;EmployeeID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;od&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;DENSE_RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;od&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;SalesRank&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Employees&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
    &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeID&lt;/span&gt;
    &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;OrderDetails&lt;/span&gt; &lt;span class="n"&gt;od&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;od&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderID&lt;/span&gt;
    &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;Products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;od&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ProductID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ProductID&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmployeeID&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;EmployeeSales&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;SalesRank&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that this query first joins the "Employees", "Orders", "OrderDetails", and "Products" tables on the respective ID fields. &lt;/p&gt;

&lt;p&gt;It then groups the results by &lt;code&gt;EmployeeID&lt;/code&gt; and calculates the total sales for each employee (which is the sum of the product of &lt;code&gt;Quantity&lt;/code&gt; and &lt;code&gt;Price&lt;/code&gt; for each order detail). &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;DENSE_RANK()&lt;/code&gt; function is used to rank the employees by their sales in descending order. &lt;/p&gt;

&lt;p&gt;Finally, the outer query selects the employee with a &lt;code&gt;SalesRank&lt;/code&gt; of 2, which represents the second highest sales. &lt;/p&gt;

&lt;p&gt;Do well to replace the table and column names if they are different in your database. &lt;/p&gt;

&lt;p&gt;If you want to get the employee name instead of the ID, you can replace &lt;code&gt;e.EmployeeID&lt;/code&gt; with &lt;code&gt;e.EmployeeName&lt;/code&gt; in the SELECT clause, assuming &lt;code&gt;EmployeeName&lt;/code&gt; is the correct column name in your "Employees" table.&lt;/p&gt;

&lt;p&gt;In conclusion, ChatGPT makes work easier and faster. But don't rely too much on it. You can further instruct it to do more for you if you are not satisfied. &lt;/p&gt;

</description>
      <category>writing</category>
      <category>learning</category>
      <category>python</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
