Well, I didn't intend for this to become a preachy-blog. Just kind of happened, I guess.
So this weekend, I got a boatload of work done, and also did another solid boatload of Tai Chi. Major workshop this weekend with the school's Grand Master. Good guy. I liked him.
E is unceasingly cute and annoying at the same time. I've got to get some sound clips of her and I playing the blues. I play, she sings. She likes to sing about "Fruit snacks in my bed...", and follows it up with, "I got the fruit snack blues..." Oh, yeah.
Killer schedule today. Working from home for a while so K can go see the doctor, picking up E from school, meeting with J from TR to get an estimate on the roof... Ugh. I'm sort of glad I'm not in Tai Chi class this month, and next month. I've got a mountain of things to do. It was, admittedly, kind of a time-suck. An enjoyable time-suck, though, and I'll be looking forward to going back. I get to learn water-boxing this time. (No, it's not done in a pool.)
In other news, in my efforts to start (again) learning a little Japanese, I recently discovered Japanese radio online. I listened to IIL yesterday for most of the morning, and am doing so again today. It's a nighttime slot, that repeats about once each hour. Not too bad, though, since I only understand about every 15th word. :-) I may troll around for other stations today.
And finally, a little bit of tech: I learned two new things yesterday. 1, how to use table aliases in a SQL query, and I wrote my first three-table join. Yikes.
Back up a second for those who don't know much SQL. A three-table join is where you take three separate tables (like spreadsheets) of information. Each table has a column that appears in another table. Say for example, you want to know how much a certain customer purchased in widgets last month for your shop. You have one table that shows customer info (CUSTOMERS), one that shows sales (SALES), and one that shows parts information (PARTS). You need to get the customer name from the CUSTOMERS table, the sales of that part from the SALES table, and the part name from the PARTS table. You need to do a three table join.
Aliases help cut down on the amount of typing you have to do. You can make an alias for a table in the FROM clause of your SQL statement. aliases can be as short as one letter. For example, if you're selecting a customer name, sale number, part name, and cost, then you can do either this:
select CUSTOMERS.NAME, SALES.SALE_NUM, PARTS.NAME, PARTS.RETAIL_COST from CUSTOMERS, SALES, PARTS where (we'll get to this in a minute.)
Or, you can do this:
select c.name, s.sale_num, p.name, p.retail_cost from customers c, sales s, parts p where...
Nice, isn't it? So now we have aliases, but we still haven't joined our tables yet. Here's how. We know that the customer name in the CUSTOMERS table matches the customer name in the SALES table. The part number in the SALES table matches the part number in the PARTS table. So we just have to make sure that those all line up. As long as the customer name in one table equals the customer name in the other, we're fine, and same for the part number. I.E.:
where c.name = s.name and s. partnum = p.partnum
Remember, too, that we're looking for a particular part's sales, so you'd also need to add
and p.name = 'Widgets'
The result is this:
select c.name, s.sale_num, p.name, p.retail_cost from customers c, sales s, parts p where c.name = s.name and s. partnum = p.partnum and p.name = 'Widgets'
Now we'll get a list of each sale of a Widget. We could also add GROUP BY and ORDER BY, as well as total columns, to make the info more useful. Maybe more on that, later.
See you.
-D.
No comments:
Post a Comment