-- GROUP BY -- The SQL GROUP BY Statement -- The GROUP BY statement groups rows that have the same values into -- summary rows, like "find the number of customers in each country". -- The GROUP BY statement is often used with -- aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group -- the result-set by one or more columns. -- GROUP BY Syntax -- SELECT column_name(s) -- FROM table_name -- [WHERE condition] -- [GROUP BY column_name(s)] -- [ORDER BY column_name(s)]; -- HAVING -- The SQL HAVING Clause -- The HAVING clause was added to SQL because the WHERE keyword -- cannot be used with aggregate --functions. -- HAVING Syntax -- SELECT column_name(s) -- FROM table_name -- [WHERE condition] -- [GROUP BY column_name(s)] -- [HAVING condition] -- [ORDER BY column_name(s)]; --------------------------------------------------------------- --1. Return the number of events by genders. --2. Return the number of events by names. --3. Return the number of countries by continents. --4. Return the number of countries by continents. Omit the NULL value from the output. --5. Return the number of countries by continents. Return a continent only if it has more than 30 countries. --6. Return the name of each continent, and the minimum, maximum and average of the area. --7. Return a continent only if the average population is less than 500000. --8. Return the name of each continent and the number of countries. Return a continent only if the average population is less than 500000. --9. Return the number of events of each name and gender combination. --------------------------- --NVL() -- The NVL() function allows you to replace null -- with a more meaningful alternative in the results of a query. --1. Return the name, the population and the continent of country Cook Islands. --2. Return the name, the population and the continent of country Cook Islands. Replace the missing continent name with string 'unknown'. --3. Return the name, the population and the continent of each country. Replace the missing continent names with string 'unknown'. --4. Return the name, the population and the continent of each country. Replace the missing continent names with string 'unknown' and the missing population values with 0. ------------------------------------------ --LOWER(), UPPER(), INITCAP() -- lower() - Convert the text to lower-case -- upper() - Convert the text to upper-case --examples --CONCATENATION --examples --CONCAT() --example ---------------------------------------- --SUBSTR() --example ------------------------------------- --DUAL Table: --The DUAL is special one row, one column table present by default in all Oracle databases. The owner of DUAL is SYS (SYS owns --the data dictionary, therefore DUAL is part of the data dictionary.) but DUAL can be accessed by every user. The table has a --single VARCHAR2(1) column called DUMMY that has a value of 'X'. --There may be a situation where we want to query something that is not from a table. For example, getting the current date or --querying a simple arithmetic expression like 2+2. Examples: select 2*3 from dual; ------------------------------------- --REPLACE() -- The REPLACE() function replaces all occurrences -- of a substring within a string, with a new substring. -- Syntax: -- REPLACE(string, old_string, new_string) --example -------------------------------- --INSTR() --example ----------------------------------------- --Date functions --SYSDATE --example SELECT SYSDATE FROM dual; --MONTHS_BETWEEN() --example --ADD_MONTHS() --example --NEXT_DAY() --example --LAST_DAY() --example --EXTRACT() --example ---------------------------- -- TO_CHAR function converts DATETIME or DATE values to character string values. -- TO_DATE function converts date strings in various formats to a date integer value, with data type DATE.