# HiveSQL for Microsoft Excel

This ste&#x70;*-*&#x62;y-step tutorial will show how to use Microsoft Excel to retrieve data from the HiveSQL database and present your result in a simple but nice pivot chart.

#### Writing a SQL query <a href="#writing-a-sql-query" id="writing-a-sql-query"></a>

Let’s say for example you want to see how many transactions have been issued each month on the blockchain. The SQL query to get such information will be:

```
SELECT
    YEAR(Blocks.timestamp) AS [Year],
    MONTH(Blocks.timestamp) AS [Month],
    COUNT(*) AS [Transactions]
FROM
    Transactions
    INNER JOIN Blocks ON Transactions.block_num = Blocks.block_num
GROUP BY
    YEAR(Blocks.timestamp),
    MONTH(Blocks.timestamp)
```

**Retrieving data with Excel**

*Start Excel, go to the Data tab and select SQL Server as your data source*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pIGcZzSeIKcHWJlyb%2Fimage.png?alt=media&#x26;token=7e1d0592-f1dc-495d-a153-087d71995640" alt=""></div>

*The Data Connection Wizard will be displayed*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pI3kuQeFtDMrUMIiU%2Fimage.png?alt=media&#x26;token=84d2eb92-482c-46ef-9224-970403883390" alt=""></div>

*Enter the connection information in the wizard dialog box as shown and click "Next"*

{% hint style="info" %}
*Use your **HiveSQL account** login and password (see* [*Register your HiveSQL account*](https://docs.hivesql.io/register-your-hivesql-acount)*)*
{% endhint %}

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pJl24O8PXUXiSD15S%2Fimage.png?alt=media&#x26;token=986fdfa2-7ac5-4a73-a6c2-f8b9a2098cfb" alt=""></div>

*Select any table (it doesn’t matter at this stage) and click '"Finish" to close the wizard*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pK0DxqCYTtS-AB9u3%2Fimage.png?alt=media&#x26;token=9743b732-8f58-43ae-84e8-58d33fe723c4" alt=""></div>

*Click on* *"Properties"*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-MaUYCuRcMIzUXfgdlB0%2F-MaUZG3GbmgMaQWon2yt%2Fimage.png?alt=media&#x26;token=a00dab8a-6b40-48b8-879a-3b081c2f7a01" alt=""></div>

*Select the "Definition" tab and* c*heck the "Save Password" checkbox to avoid Excel asking you for credentials each time you connect to the database.*

![](https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pMzfz6R6OiT8ZfjzN%2Fimage.png?alt=media\&token=5c027ed6-c2b3-425e-97db-c73236512609)

*You can safely ignore the warning if your computer is secure*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pNS0WLUVgzLRXpNzZ%2Fimage.png?alt=media&#x26;token=e303bb42-0ad6-41c5-8f8b-9dc5810901e9" alt=""></div>

*Open the "Command type" dropdown control and select "SQL"*

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pOIE2BijdqlSGoLUN%2Fimage.png?alt=media&#x26;token=03afebf4-30fe-45d3-8868-4068c5d4a060" alt=""></div>

*Paste your SQL query and click* `OK`

![](https://images.hive.blog/0x0/http://i.imgsafe.org/7e1f6d273e.png)\
\&#xNAN;*Select the type of data presentation you want in Excel.*

#### Finalizing the presentation <a href="#finalizing-the-presentation" id="finalizing-the-presentation"></a>

Now that you got all your data, make a nice chart.

<div align="left"><img src="https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pRIW5ki4CTA-C0zjQ%2Fimage.png?alt=media&#x26;token=81a9482e-8cf1-4c6f-80fa-175b532146c8" alt=""></div>

*Organize your data fields in the pivot properties*

![](https://2883586225-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWGLUXcek_KgwMLAO9R%2F-M_pHV_ocK0v8lvRMuaZ%2F-M_pRiD9vyso44AgGR8K%2Fimage.png?alt=media\&token=ba3fde2d-9870-475b-8695-78558dd6e5ba)

You now have created your report using the blockchain data.
