CST 363 - Week 2
Hey everyone!
We are back with an update of this online journey. This has been a fun week. We learned so many new things. I find SQL easier to grasp onto, compared to other coding languages. It just seems very similar to our normal English language.
This week, we learned different types of joins, aggregation, and views. The labs really helped understand the concepts, after reading about them in Zybooks, and listening to Professor's lectures. The homework assignment seemed to go smoother as well, because of the practice we got in the lab assignments.
1. 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.
English: Find all orders where the order amount falls within any of the promotion ranges and display the order details along with the applicable promotion information.
SQL: SELECT o.OrderID, o.CustomerID, o.OrderAmount, p.PromotionID, p.Discount
FROM Orders o
JOIN Promotions p
ON o.OrderAmount BETWEEN p.MinAmount AND p.MaxAmount;
Comments
Post a Comment