Skip to content

Commit

Permalink
Feedback from meet-up inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias2342 committed Nov 4, 2014
1 parent 5824c54 commit 1ed65ed
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 28 deletions.
2 changes: 2 additions & 0 deletions chapter1.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ <h2>Software used</h2>

<p>To perform a SQL query to a database, enter the command in the text field and click on <em>Execute Command</em>. As an alternative to Sqlitebrowser you can use <em>Sqliteman</em> which is a good alternative especially for Debian and Ubuntu Linux users. Please refer to the <a href="installationguide.html">installation guide</a> for details.</p>

<p></p>

<h2>Sample database</h2>
<p>As the focus of this tutorial lies on the retrieval of data from an existing database rather than creating new databases, a file <a href="databaseOTS.sqlite">databaseOTS.sqlite</a> is provided which contains all the data required later on in the course. Download this file to some location on your computer. Then you can open it in <em>DB Browser for SQLite</em> by clicking on <em>open database</em>.</p>
<p align=center><img src="screenshot1.png" alt="DB Browser for SQLite" width=650></p>
Expand Down
15 changes: 5 additions & 10 deletions chapter2.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ <h2>Simple queries</h2>
<p align=center><img src="table1.png" alt="person table" width=650></p>
<p align=center><img src="table2.png" alt="phone_contract table" width=650></p>


<p>We want to see what is in the table person:</p>
<pre>select * from person;</pre>
<p>This is too much information as we are only interested in the name:</p>
<pre>select name from person;</pre>
<p>In general:</p>
<pre>select col1, col2, ... from tablename;</pre>
<p>We can get the number of lines of results by using the count command. To get the number of entries in the person table we use</p>
<p>Note that <code>select *</code> selects <em>all</em> columns of the respective table. We can get the number of lines of results by using the count command. To get the number of entries in the person table we use</p>
<pre>select count(*) from person;</pre>
<p>Results might contain duplicates (they form a multi-set). We can get only the distinct results by</p>
<pre>select distinct col1,col2, ... from tablename;</pre>
Expand All @@ -37,12 +36,8 @@ <h2>Constraints</h2>
<pre>select name, residence from person where age > 30;</pre>
<p>For the different type of data, different constrains make sense. For all kind of data, we can check for equal <code>=</code> and not equal <code>!=</code>. For numbers, one can also compare for <em>larger</em> <code>></code>, <em>larger or equal</em> <code>>=</code>, <em>smaller</em> <code><</code>, <em>smaller or equal</em> <code><=</code>.</p>

<<<<<<< HEAD
<p>For text, we use <code>like</code>, to find entries where the text value in a column contains a string, where you can use the <code>%</code> as a wild-card for unknown parts of a word. E.g. if you search for <code>'%an%'</code>, the following words would fit: B<strong>an</strong>ana, f<strong>an</strong>tasy. Note that in SQLite, the <code>like</code> operator is <em>case insensitive</code> by default.
<p>For text, we use <code>like</code>, to find entries where the text value in a column contains a string, where you can use the <code>%</code> as a wild-card for unknown parts of a word. E.g. if you search for <code>'%an%'</code>, the following words would fit: B<strong>an</strong>ana, f<strong>an</strong>tasy. Note that in SQLite, the <code>like</code> operator is <em>case insensitive</em> by default.

=======
<p>For text, we use <code>like</code>, to find entries where the text value in a column contains a string. The string should be surrounded by single quotes <code>'</code>, and you can use the <code>%</code> as a wild-card for unknown parts of a word. E.g. if you search for <code>'%an%'</code>, the following words would fit: B<strong>an</strong>ana, f<strong>an</strong>tasy, but not <strong>An</strong>na, since this is a Capital A.</p>
>>>>>>> 0051abf36686309bb132c5e0d7ed6717a9bb879b
<p class=question>3.) Get all people whose names contains "oh".</p>
<p>In SQLite the <code>></code>,<code><</code>,<code>=</code> operators for dates, do an <em>lexicographical</em> comparison, not a <em>numeric</em> one. This means that if there is an inconsistent representation of dates, the comparison might fail even though the two values represent the same dates. E.g. if once the format <code>"2014-10-23"</code> and once the format <code>"2014/10/16"</code> is used. Note that here double quotes <code>"</code> are used instead of single quotes <code>'</code>.</p>
There is a table named <code>flight</code> containg flight data. The column with the dates is called <code>date</code>.
Expand All @@ -59,7 +54,7 @@ <h2>Constraints</h2>
<p>Constraints can be combined by the logical operator <code>and</code> and the operator <code>or</code>.</p>
<p class=question>6.) Find all people whose first name is Carlos and who are older than 20 years.</p>
<p>There is another table which is called <code>phone_contract</code>. The column containing the status (active, non-active) is called <code>status</code>.</p>
<p class=question>7.) Find out, how many contracts there are and how many accounts are active.</p>
<p class=question>7.) Find out, how many contracts there. With a second query find out how many of them are and how many accounts are active.</p>

<h2>Results from more than one table</h2>
<p>Usually, it is necessary to get information which is spread over more than one table. For example, you may want to know the names of the people who have an active phone contract.</p>
Expand All @@ -73,7 +68,7 @@ <h2>Results from more than one table</h2>
<pre>select p.name, c.phone_number from person p, phone_contract c
where c.name = p.name;</pre>
<p>As we did not want to write the complete table name, we have defined and abbreviation in the <code>from</code> clause (<code>person p</code>).</p>
<p class=question>9.) Find all names who have an active phone contract.</p>
<p class=question>9.) Find all names and ages of persons who have an active phone contract.</p>
<p class=question>10.) Find all names and phone numbers of people who are older than 30.</p>

<h2>Sub-queries</h2>
Expand All @@ -91,7 +86,7 @@ <h2>Sub-queries</h2>
<p>If you have no more question concerning basics SQL queries, you can procede to the next chapter and solve <a href="chapter3.html">the theft of the Mona Lisa</a>.</p>

<p><a href="chapter2_solutions.html">Solutions</a></p>
Sub

<p><a href="index.html">Back to start</a></p>

</body>
Expand Down
4 changes: 2 additions & 2 deletions chapter2_solutions.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ <h1>Solutions - SQL Basics</h1>

<li><p class=answer>Use</p>
<pre>
select person.name from phone_contract where status = 'active'
and person.name = phone_contract.name;
select person.name, person.age from person, phone_contract
where person.name=phone_contract.name and status = 'active';
</pre></li>

<li><p class=answer>Use</p>
Expand Down
15 changes: 4 additions & 11 deletions chapter3.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Which tables are there? - System tables</h2>
Remarks: In other databases (e.g. Oracle, DB2 etc.) this meta information is stored differently, i.e. the system tables are always called differently. Sometimes there is more than one system table. When working with another database than sqlite you need to google for the names of the system tables of that database.</p>

<h2>How to find the thief</h2>
<p>For finding the thief we have the following plan:</p>
<p>When you follow the tutorial you will step-by-step:</p>
<ol>
<li>Find out, who was in Paris at that time.</li>
<li>The thief was probably not working alone. Is there any suspicious communication during the time in question?</li>
Expand Down Expand Up @@ -60,19 +60,12 @@ <h2>How information of different tables are cleanly connected: Key constraints</

<h2>Who is the thief? - Order by and group by</h2>
<p>To find out who is the thief, check the text messages stored by the mobile phone providers.</p>
<<<<<<< HEAD

<p class=question>23.) How is the name of the table containing the text messages and the one containing phone contracts?</p>
<p class=question>24.) Get all text messages  which where sent between 2014-10-20 and 2014-10-25.
<p class=question>25.) Get all phne contract ids where the <code>phone_contract.person_id</code> is equal to the id of one of the suspects.</p>
<p class=question>26.) Get all text messages where the sent date is the 23.10.2014 and the sender or receiver is one of our suspects.</p>

=======
<p class=question>23.) What are the names of the table containing the text messages and the one containing phone contracts?</p>
<p class=question>24.) Get all text messages  which where sent between 2010-10-20 and 2010-10-25.
<p class=question>25.) Get all contract ids where the <code>contract.name_id</code> is equal to one of the persons from the results of question 15.</p>
<p class=question>26.) Get all text messages where the sent date is the 23.10.2014 and the <code>contract_sender_id</code> is equal to the contract ids where the <code>contract.name_id</code> is equal to one of the persons from the results of question 15.</p>
>>>>>>> 0051abf36686309bb132c5e0d7ed6717a9bb879b
<p class=question>25.) Get all contract ids where the <code>contract.name_id</code> is equal to one of the persons from the results of question 19.</p>
<p class=question>26.) Get all text messages where the sent date between 2010-10-20 and 2010-10-25 and the <code>contract_sender_id</code> is equal to the contract ids where the <code>contract.name_id</code> is equal to one of the persons from the results of question 19.</p>

<p>You see that you got all the required information but the output looks kind of chaotic. You can order an result set according to a column with an <code>order by</code> phrase. The query to get all text messages from 21.10.2014 ordered by time reads</p>
<pre>
select message from messages where sent like '2014-10-21%'
Expand Down
3 changes: 1 addition & 2 deletions chapter3_solutions.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<h1>Solutions - The theft of the Mona Lisa</h1>



<ol start="12">
<li><p class=answer>Use the <code>select</code> command on the table <code>sqlite_master</code> and <code>pragma table_info</code> on all tables present in the database.</p></li>

Expand Down Expand Up @@ -108,7 +107,7 @@ <h1>Solutions - The theft of the Mona Lisa</h1>
<pre>
select id from phone_contract where phone_contract.person_id
in (select distinct person.id from person, flight
where residence = 'Paris' or
where residence = 'Paris' or
(flight.person_id = person.id
and dest_city = 'Paris' and date < "2014-10-23"
and flight.name in (select flight.name from flight
Expand Down
2 changes: 1 addition & 1 deletion databaseOTS.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ INSERT INTO bank_transaction values (430,2655480,null,'Cash withdrawal',443.17);


INSERT INTO person values (100, 'Philipp', 'Hamburg', 42);
INSERT INTO person values (101, 'Phillipp', 'Mumbai',75);
INSERT INTO person values (101, 'Philip', 'Mumbai',75);
INSERT INTO person values (102, 'Carlos', 'Paris', 21);
INSERT INTO person values (103, 'Wei', 'Paris', 36);
INSERT INTO person values (104, 'John', 'Sydney', 37);
Expand Down
Binary file modified databaseOTS.sqlite
Binary file not shown.
4 changes: 2 additions & 2 deletions installationguide.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ <h2>Microsoft Windows</h2>

<p>To get <em>SQLite</em>, download <a href="http://www.sqlite.org/2014/sqlite-shell-win32-x86-3080701.zip">a zip archive</a> from the <em>SQLite</em> project web page. This zip-archive contains an executable file <em>sqlite3.exe</em>. Copy this file to some place on your computer (the desktop should be fine). Double-click on it to start the program.</p>

<p>To get the graphical user interface <em>DB Browser for SQLite</em>, formerly called <em>Sqlitebrowser</em>, just download the <a href="https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.4.0/sqlitebrowser-3.4.0-win32.exe">executable installer file</a>. Double-click in it to run it and agree to the license to finish the installation.</p>
<p>To get the graphical user interface <em>DB Browser for SQLite</em>, formerly called <em>Sqlitebrowser</em>, just download the <a href="https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.4.0/sqlitebrowser-3.4.0-win32.exe">executable installer file</a>. Double-click in it to run it and agree to the license to finish the installation. Unfortunately, the installer does not work with <em>64bit Windows</em>. If you use this operating sytem, you can download the <a href="http://rp.oldsch00l.com/sqlitebrowser/sqlitebrowser.exe.xz">zipped file</a>, save the contained .exe-file to some location on your computer and run it by double-clicking on it (no installation required).</p>

<h2>MacOS</h2>
<p>To get <em>SQLite</em>, download <a href="http://www.sqlite.org/2014/sqlite-shell-osx-x86-3080701.zip">a zip archive</a> from the <em>Sqlite</em> project web page. This zip-archive contains an executable file <em>sqlite3</em>. Copy this file to some place on your computer (the desktop should be fine). Right click on the file and select <em>open</em> and confirm the security message.</p>
<p>To get <em>SQLite</em>, download <a href="http://www.sqlite.org/2014/sqlite-shell-osx-x86-3080701.zip">a zip archive</a> from the <em>Sqlite</em> project web page. This zip-archive contains an executable file <em>sqlite3</em>. Copy this file to some place on your computer (the desktop should be fine). Right click on the file and select <em>open</em> and confirm the security message. On some systems, this procedure will fail for security reasons. In this case you need to allow the installation of <em>unsigned</em> applications in the system preferences.</p>

<p>To get the graphical user interface <em>DB Browser for SQLite</em>, formerly called <em>Sqlitebrowser</em>, just download the <a href="https://github.com/sqlitebrowser/sqlitebrowser/releases/download/v3.4.0/sqlitebrowser-3.4.0.dmg">MacOS drive image</a>. Open it and copy the contained file to some location on your computer. Right click on the file and select <em>open</em> and confirm the security message.</p>
<h2>Linux</h2>
Expand Down

0 comments on commit 1ed65ed

Please sign in to comment.