Wednesday, September 11, 2024

CST363 - Week 2

This week we were tasked to answer the following questions

SQL has the flexibility to join tables on any column(s) using any predicate (=, >, < ). Most of the time the join will use equality between a primary and foreign key. Think of example where joining on something other than keys would be needed. Write the query both as an English sentence and in SQL. If you can't think of your own example, search the textbook or internet for an example.

I think one way to look at this in English would be sales in a store. For example, we want a list of the total stock of a product along with the total number of that product the store has sold.

In SQL, I think it would look like this:

SELECT p.product_name
    SUM(p.quantity) AS current_stock
    SUM(s.quantity AS total_sold
FROM products AS p
LEFT JOIN sales AS s ON  p.product_name = s.product_name
WHERE p.product_name = 'apples'
GROUP BY p.product_name;


What is your opinion of SQL as a language? Do you think it is easy to learn and use? When translating from an English question to SQL, what kinds of questions do you find most challenging?

Aside from the basic SELECT SQL problems, I find SQL fairly difficult to understand compared to languages like Java or Python for some reason. I particularly struggle with JOIN problems and often have to refer to documentation. There are other aspects that I constantly get mixed up, and it just doesn't come as easily to me for whatever reason.

No comments:

Post a Comment

CST462S - Service Learning Experience

With the first half of my Summer semester now coming to a close, I am submitting my final assignments and preparing for the upcoming class i...