Command Function as Used to Rename A

download Command Function as Used to Rename A

of 1

Transcript of Command Function as Used to Rename A

  • 8/14/2019 Command Function as Used to Rename A

    1/1

    COMMAND FUNCTION

    AS Used to rename a column. Most helpful when you are calculating something in your select statement.(note: if you are using more than one word or want mixed case use )

    SELECT (hours_worked * hourly_wage) AS Salary FROM employee

    AVG, MAX,MIN, SUM

    These are 3 of the 4 Aggregate functions. You can use them in the select statement, group by statementand having statement

    SELECT AVG(price) FROM products

    COUNT This is the fourth aggregate function. You use this to count the number of rows that meet some criteria.

    When you use the * with count it counts each row, when you put an attribute in the () it counts

    SELECT COUNT(*) FROM employee WHERE state = MA

    DELETE This is used to delete a row in your table

    DELETE FROM employee WHERE state = MA

    DISTINCT This removes duplicates in your output.

    SELECT DISTINCT state FROM employee

    IN, NOT IN This compares a value to a list of other values. It is very helpful when doing subqueries and you do notknow how many values will be returned.

    SELECT employee_id

    FROM employee WHERE position IN(SELECT position FROM employee WHERE salary > 50000)

    INSERT Used to insert data into a table. Note: If you are not adding something to every column you can either listout the attribute names you have data for and then the data you want in them, OR put in a space holder byusing . Dates are always in the following format and they use single quotes 01-JAN-1999

    INSERT INTO employeeVALUES (Fred,,Flinstone)

    LIKE This is used for pattern matching. % is used for any number of characters in a string and _ is used for asingle character. When you use Like you MUST have your capitalization correct for a match to be found.

    Select employee_fname FROM employee WHERE employee_fname LIKE %fred% or employee_fnam

    LIKE %Fred%ORDER BY This puts your columns in order. If you want to order your output by more than one column put the first

    column first in the order by statement and the second column next.

    SELECT employee_lname, salaryFROM employeeORDER BY salary, employee_lname

    SELECT ALL SQL queries start with SELECTIf you need to output a calculated or derived value you can do that in the select statement

    SELECT employee_fname, (salary*hours_worked) AS Pay CheckFROM employee

    UPDATE This is used to modify the data in your table.

    UPDATE shr SET shrqty = shrqty*1.1WHERE shrfirm = 'Nigerian Geese';

    WHERE This is used to restricting your out put based on something

    SELECT employee_lnameFROM employeeWHERE salary > 50000