However, in SQL you can only perform arithmetic across columns on values in a given row. You can perform arithmetic in SQL using the same operators you would in Excel: +, -, *, /. Try it out See the answer Arithmetic in SQL Write a query that only shows rows for which the month_name starts with the letter "N" or an earlier letter in the alphabet. It's worth noting that most dictionaries would list 'Ja' after 'J' as well. "January is included in the results-shouldn't I have to use month_name >= 'J' to make that happen?" SQL considers 'Ja' to be greater than 'J' because it has an extra letter. You may have noticed in the above query that selecting month_name > 'J' will yield only rows in which month_name starts with "j" or later in the alphabet. The way SQL treats alphabetical ordering is a little bit tricky. Note: SQL uses single quotes to reference column values. If you're using an operator with values that are non-numeric, you need to put the value in single quotes: 'value'. There are some important rules when using these operators, though. For example, run the following query and you'll notice that none of the January rows show up: SELECT * = and != make perfect sense-they allow you to select rows that match or don't match any value, respectively. Try it out See the answer Comparison operators on non-numerical dataĪll of the above operators work on non-numerical data as well. When you're ready, try out the practice problems.ĭid the South Region ever produce 20,000 or fewer housing units in one month? Try some values other than 30 to get a sense of how SQL operators work. Try running that query with each of the operators in place of >. to return only the rows where the West Region produced more than 30,000 housing units (remember, the units in this data table are already in thousands): SELECT * The easiest way to understand them is to start by looking at a list of them: Equal to The most basic way to filter data is using comparison operators.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |