Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

ADVANCED SQL COMMANDS

Timestamps and Extract :

it is more useful in creating databases and tables..

we can only remove tthe timestamptz whenever we need in the tabless but... we cant add it back

SELECT NOW() -- > Gives date time and timezone

TIMEOFDAY() --> Gives in charchters all date time and timezone

CURRENT_TIME --> Only gives the current time

CURRENT_DATE --> gives only the current date

EXTRACT() :

Allows to extract the only sub components of time like .. year,month,day,week,quater.. from data

SYNTAX ::

EXTRACT(YEAR FROM coloum)

AGE() :

calculates the age of the data ..

SYNTAX :::

AGE(coloum)

RETURNS :

13 YEARS 1 MON 5 DAYS 1:34:12.003423

TO_CHAR() :

converts datatype to text ..

SYNTAX :::
TO_CHAR(date, 'mm-dd-yyyy')

DOW :

used to get the single day if want from time stamp...

SYNTAX ::

EXTARCT(dow form coloum) = 1

here sunday starts from 0 .. monday 1 tuessday 2 .... . ....so on

MATHEMATICAL FUNCTIONS :

can use the mathematical functions like addition,sub,div.. all FYI use the google to know the more
syntax..

STRING FUNCTIONS AND OPERATIONS

can use the string as we want all FYI use the google to know the more syntax..

for concatination we use ||

Sub Query

used to get the extra answers thaan we get and filter the data..

use double SELECT in this sub query..

first sub query is runned after that normal ..

EXAMPLE ::

SELECT student_name,grade FROM student_grades

WHERE grade > (SELECT AVG(grade) FROM student_grades)

EXISTS :

USED TO test for existence of rows in subquery

SYNTAX ::
EXISTS(... .)

EXAMPLE ::

SELECT coloum FROM table

WHERE EXISTS(SELECT COLOUM FROM table WHERE condition)

SELF JOIN :

Used to join the two same tables i.e.,,, join the same table

use AS compulsory becaause of the same taable ..

EXAMPLE :::

SELECT Table_A.col,TableB.col FROM table AS TableA

JOIN table AS TableB

ON TableA.somecol = TableB.othercol

You might also like