MySQL for the Internet of Things
Chapter 5 ■ MySQL priMer ■Tip Best practices suggest using a primary key on a character field to be suboptimal in some situation ...
Chapter 5 ■ MySQL priMer mysql> SELECT * FROM plant_monitoring.plants; +------------------------+--------------+------------- ...
Chapter 5 ■ MySQL priMer There are additional clauses you can use including the GROUP BY clause, which is used for grouping rows ...
Chapter 5 ■ MySQL priMer Now let’s say we want to see the results of our result set ordered by sensor value. We will use the sam ...
Chapter 5 ■ MySQL priMer Notice I specified the columns before the data for the row. This is necessary whenever you want to inse ...
Chapter 5 ■ MySQL priMer Removing Data Sometimes you end up with data in a table that needs to be removed. Maybe you used test d ...
Chapter 5 ■ MySQL priMer This command adds an index on the plant_name column. Observe how this affects the table. CREATE TABLE p ...
Chapter 5 ■ MySQL priMer This trigger will execute before each insert into the table. As you can see in the compound statement ( ...
Chapter 5 ■ MySQL priMer Listing 5-7. Simple JOIN Example mysql> SELECT Name, Continent, Language FROM Country JOIN CountryLa ...
Chapter 5 ■ MySQL priMer This discussion on joins touches only the very basics. Indeed, joins are arguably one of the most diffi ...
Chapter 5 ■ MySQL priMer What aBOUt ChaNGING OBJeCtS? you may be wondering what you do when you need to modify a table, procedur ...
Chapter 5 ■ MySQL priMer Step 1: Describe the Data The first thing you should do when designing a database is to describe the da ...
Chapter 5 ■ MySQL priMer CREATE TABLE readings ( id int(11) NOT NULL, moisture float DEFAULT NULL, temperature float DEFAULT NUL ...
Chapter 5 ■ MySQL priMer Finally, notice that while I added a primary key, in this case the AUTO_INCRMENT data type to the plant ...
Chapter 5 ■ MySQL priMer column in the table, we must first insert the data about the plant and then query the table for its ID. ...
Chapter 5 ■ MySQL priMer Step 3: Design the Queries or Questions for the Database Whenever designing a database, I make it a poi ...
Chapter 5 ■ MySQL priMer The following WHERE clause demonstrates how to do this. Notice we pass in the event_time column to the ...
Chapter 5 ■ MySQL priMer Example 2: A Complex Query Let’s now look at a more complex query. Or rather one that is simple in its ...
Chapter 5 ■ MySQL priMer So, this tells us that, for today, plant IDs 1 and 3 are dry. But we’re not done! Consider there are mu ...
Chapter 5 ■ MySQL priMer We will also limit the columns in the result to just the id. The following query shows an example SELEC ...
«
5
6
7
8
9
10
11
12
13
14
»
Free download pdf