Tutorial | DBeaver SQL Client - #2 How to search, filter and SQL query

in utopian-io •  7 years ago  (edited)

In my previous tutorial about DBeaver SQL Client you've learned how to install and connect with SteemSQL

In this tutorial I'll show how to use DBeaver to do basic searches, filter content, generate and run SQL queries and export the results.

e.png

Again I'm using SteemSQL Data Base as an example, since we have the SteemSQL Date Base running a lot of steemians started to do analysis with these data so I think is very useful.

Here is the link of part #1 DBeaver tutorial:
#1:Tutorial | DBeaver SQL Client - #1 How to Install and Connect with SteemSQL

Let's begin, open DBeaver:
p.png
If you followed the steps in part #1 you should get this screen above.

For this tutorial I'll search and filter information in the Data Base with the objective to produce analysis over one subject.

Let's say I want to do one over account creations in Steemit:

Searching
The easiest way to search is using the 'Data Base Navigator' on your left panel:
q.png
As I pointed before all data for steem is stored in the 'dbo' file, select 'dbo'. Select 'views' to see the tables inside. We are looking for accounts creations, this info is stored at 'TxAccountCreates' , select. You can see all columns that 'TxAccountCreates' stores, and the data type of each one.
-Double-click 'TxAccountCreates'

Now let's take a look at the data inside this table:
r.png
Click 'Data' tab. And wait till it loads

All columns were feed with the data:
s.png
You can notice that Dbeaver only fetched 200 rows. This panel is mostly to check the content before apply any filters, check data type, how many inputs and so...

Let's check how many rows are in this table, witch will give us the total number of account creations so far:
t.png
Right side of the panel, Click 'Calculate total row count'. This action will not feed the columns with all rows, only calculate them.

This action, and most actions we perform in the 'Data' tab, may take a few moments to load:
u.png
Always wait to complete before performing another action or you'll get errors. Click 'cancel' if you want to stop it
Result:
v.png
542.299 rows. Or 542.299 accounts creations.

How to filter Data
OK, we find the data that we were looking for. Now let's say I want to analyse accounts creations only in a period of time. For that I'll need to apply filters! To keep it simple I'll seek for accounts creations in 2018 so far:
The column that stores the date of an account creation is 'timestamp'
x.png
Right mouse click on 'timestamp' > 'Order / Filter' > 'timestamp >...'
Input filter parameter:
y.png
As the data type for 'timestamp' is 'datetime' we need to put in this format above.

Result:
Notice at top right that DBeaver created one command line for this action we performed. This is the SQL criteria for the filter we just did. Keep that in mind, we are going to use this line later when dealing with SQL queries
w.png
At bottom left we can see how many rows are inside our filter parameter for this column - 11.287, witch means, that's the number of accounts created in 2018 so far!
Nice we got what we were looking for!

Now we need to transfer that result to an 'Office' software in order to produce charts and analysis.
To do that let's use the 'Advanced Copy' DBeaver feature:

First, we need to fetch all rows in:
z.png
Click 'Fetch all rows' and wait till it loads (may take a few seconds)

Result:
za.png

Use Multiple Select (hold 'CTRL' + mouse click) on columns to be copied:
Here I'm selecting only 'delegation', 'creator', 'new_account_name' and 'timestamp' columns
zb.png
Right mouse click > 'Advanced Copy' > 'Advanced Copy'

Click 'OK'
zc.png

Go to your prefer 'Office' software:
zd.png
Rigth mouse click 'Paste'

Here I'm using 'LibreOffice':
ze.png
Click 'OK'

Result:
zf.png
Done. Now you can work with it, produce charts and make conclusions on what you got.

Working with SQL queries
As I pointed before, the actions we perform in 'Data' tab creates SQL lines.
Let's go back to our 'Data' tab to check it out:
zg.png
This is the line for our filter criteria, but is not the whole SQL query.

Single Click on 'TxAccountCreates':
Now you can see the whole query
zh.png
To open the SQL Editor Double Click on 'TxAccountCreates'

SQL Editor:
zi.png
Here it is our SQL Editor with our SQL query filtering 'timestamp'. To run the script Click 'Execute SQL statement'

Result:
zj.png
We got the data but I want to gather only 'delegation', 'creator', 'new_account_name' and 'timestamp' columns

Let's do that by typing a code line in the SQL Editor script:
zk.png
As you can see here DBeaver will help with that giving you suggestions and settings. When I started to write 'delegation' he auto completed for me with the columns names available for this query.

Finish the code line and click 'Execute SQL statement' again:
zl.png
Wait till it loads

Result:
zm.png
That's it. You can work in SQL Editor to easy write queries and test them before apply in your project, play with it.

Saving the script:
zp.png
At Top , on main tab settings. Click 'SQL Editor' > 'Save SQL Script'

Choose your destination and File name:
zq.png

Result:
zo.png
Script Saved. You can import it later or do whatever you need with this file in your project!

That's it! Now you know how to do basics with DBeaver Universal SQL Client, enjoy!

End of Tutorial

That's all for today. I hope you all enjoyed.

Thank You



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted on behalf of the dropahead Curation Team!

Thanks for following the rules.

DISCLAIMER: dropahead Curation Team does not necessarily share opinions expressed in this article, but find author's effort and/or contribution deserves better reward and visibility.

Help us giving you bigger upvotes by:

Upvote this comment!
Upvote the latest dropahead Daily Report!
Join the dropahead Curation Trail
to maximize your curation rewards!
Vote dropahead Witness with SteemConnect
Proxy vote dropahead Witness
with SteemConnect
Delegate/donate STEEM POWER to @dropahead
Do the above and we'll have more STEEM POWER to give YOU bigger rewards next time!

News from dropahead: Bye bye 25+ and 50+! Welcome 20+ 40+ and 60+!

Quality review by the dropahead Curation Team

According to our quality standards(1), your publication has reached an score of 90%.

Congratulations for your excellent work!


(1) dropahead Witness' quality standards:

- Graphic relation to the text (Choice of images according to the text)
- Order and coherence
- Style and uniqueness (Personal touch, logic, complexity, what makes it interesting and easy to understand for the reader)
- Images source and their usage license

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you

Hey @lpessin I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Obrigadas por este excelente tutorial sql coa ferramenta DBeave.
Podería aprendernos os menos habilidosos nunha prosima entrega a crear querys cruzando taboas?
Un saúdo.