The morning after drinking with Saito, I went to the staff room and was directed to a training room by a clerk. The training room only had 10 seats with Saito standing up front and Inoue sitting in front of him. Saito urged me to take a seat.
“Today, I’m going to ask you to kill each other.”
There was silence as Inoue and I didn’t know how to react to Saito’s clumsy imitation of Battle Royale.
“Tch, no excitement. Aren’t you guys from my generation? That’s enough. Today, you’ll be learning SQL.”
“Huh? Is that the database thing?”
Although I knew SQL as a word, I didn’t know anything about it specifically.
“That’s right. The reason is that our team will be in charge of spreadsheets created by engineers for a while. If we can’t process the QUERY function, we won’t be able to do anything.”
I can’t believe it. I thought engineers just programmed on black terminals, they use Excel and Google Spreadsheets as well?
“Um, may I ask a question?”
Inoue raised her hand as she asked.
“I already know SQL, so I don’t think I need to learn anything.”
“That’s obvious. You were originally an SE (Systems Engineer), right? Takahashi is the one learning and you will be the one teaching.”
Was Inoue an SE? I’m sure I asked her about it once before, but she didn’t want to seem to answer and said something like ‘I am just an ordinary office lady’ to cover it up, so I hadn’t known she was an SE. Now that it was mentioned, it made sense that she was knowledgeable about regular expressions.
“Ehh, wouldn’t it be better if Saito-san taught it?”
“Sorry, I’m on vacation today. I have a bunch of movies I need to watch. So, you’ll need to teach him how to process the QUERY function in a day. I’ll leave it to you. Good luck.”
Saying that, Saito left, leaving Inoue to take the stage with a sigh.
###################################
“Um, Takahashi-san, do you know what SQL stands for?”
“No, no idea.”
“This is no fun…can you read this?”
Inoue wrote onto a whiteboard while looking bored.
Structured Query Language
“Structured Query Language, Structured…Query? Language? I see, that’s why it’s SQL.”
“Yes and no. SQL is a language for database operations and definitions, but SQL as an international standard isn’t an acronym for anything, so the correct answer is that it is not an acronym. To be honest, I had also been taught that it stood for Structured Query Language when I learned about it, but Wikipedia says otherwise.”
Why did you make me read it them? Inoue was proud as she explained, but the information was completely irrelevant. Isn’t it fine to just use it as an acronym? Can we really trust something written on Wikipedia?
“Uh, so what’s the point of mentioning that?”
“Just a little bit of trivia. So, Structured Query Language is a structured query language…”
It was named after itself.
“As workers, we only need to process the QUERY function, so we can think of it as a language for retrieving data from a database.”
“So I have to learn a new language in one day? That seems unreasonable…”
“Don’t worry. In fact, most of it is in English, so if you’ve mastered junior high school English, you’ll be fine. For example, let’s say you have a database of workers like this.”
Name Gender Age
———- ———— ——-
Takahashi Male 27
Saito Male 43
Inoue Female 17
As Inoue was writing, it made sense that Saito was 43, but then I saw the 17 and it all lost credibility.
“Just to clarify, gender refers to the physical sex you were born with and does not define sexual preference. Even though both Takahashi and Saito are listed as male, it’s still fine for two people to fall in love.”
Stop talking about your BL hobby while pretending to be concerned about political correctness. I didn’t feel like pointing that out though. Inoue glanced at me before continuing her explanation.
“For example, if you wanted to extract workers under the age of 30 from the database, you would write this.”
select * where Age <= 30
“The result would be this.”
Name Gender Age
———- ———— ——-
Takahashi Male 27
Inoue Female 17
“‘where’ is the extraction condition. What does * mean?”
“After ‘select’ you have to specify the columns you want to display. * just specifies all columns. So, for example, if you only wanted to display name and age, you would do this.”
select Name, Age where Age <= 30
Name Age
———- ——-
Takahashi 27
Inoue 17
“By the way, if you wanted to specify the order of the data, you can use ‘order by’.”
select Name, Age where Age <= 30 order by Age
Name Age
———- ——-
Inoue 17
Takahashi 27
“If you specify to sort by age, 17 year old me will be displayed first.”
“I see, regardless of whether you’re 17 or not, I understand.”
Inoue grinned at my retort. Maybe I shouldn’t have said that.
“Another important thing you can do is to aggregate using ‘group by’. For example, if you want to calculate the number of people by gender, you would use this.”
select Gender, count(Name) group by Gender
Gender count(Name)
———— ——————-
Female 1
Male 2
“I’m the only woman and there are two men, Saito-san and Takahashi-san, so it looks like this. By the way, gender is…fine, I won’t say it again.”
“Count is like the function in spreadsheets.”
“That’s right. On that note, in this case, count(Gender) and count(Age) simply count values, so there’s no particular calculation going on. If you use a function other than count, it will look like this.”
select Gender, count(Name), avg(Age) group by Gender
Gender count(Name) avg(Age)
———— ——————– ————–
Female 1 17
Male 2 35
“As you can tell by the results, ‘avg’ takes the average. This is a range that is often used in QUERY. It’s mostly English, so if you’re used to Excel, it should feel the same as functions.”
“Well, this is easier than I though, I feel like I’ll be able to understand SQL in a day.”
Inoue’s eyebrows twitched at my words.
“Takahashi-san, just for the record.”
“Yes.”
“What I just explained was the Google Visualisation API query language used in the QUERY function. Compared to commonly used databases such as MySQL, PostgreSQL, and Oracle, it is greatly simplified and only has a few limited functions. Please be careful how you speak. Even Takahashi-san would be offended if a high school student who had just finished a class said ‘I understand everything about Excel’, right?”
I wondered where her self proclaimed 17 year old setting had gone, but she was right. I sincerely apologised and the class continued on.
※Functions
QUERY https://support.google.com/docs/answer/3093343
Click here for the Google Visualization API https://developers.google.com/chart/interactive/docs/querylanguage
Author’s Note
Here’s the start of the new volume: Engineering Spreadsheets. Look forward to it.
As a side note, I learned SQL from a book written by master Mick.
SQL Database Operations Starting from Scratch (Mick)