0% found this document useful (0 votes)
14 views

SQL

Uploaded by

chintu chintu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL

Uploaded by

chintu chintu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CREATING AN XTRA COUMN ;

1) create table ch(no int,name varchar(30),salary float); =insert into ch values(1,("chintu"),'2000');

2)alter table ch add value decimal;= update ch set no="1" where value="200";

3)

CREATING AN XTRA COUMN;

alter table grees2 add eduction varchar(20);

ADDING VSLES IN CREATEED COLUMN;

update grees2 set no="1" where eduction="btech";

aggrigate functions

1) count ;

select count(sname) from hero;

for counting the duplicate vakues in the entire colmn

select max(ssalary) as mimimummarks from hero; to show the title column name which we have to
specify asa minimiumvalue

select count(distinct sname) from hero;

2) sum;

select sum(ssalary) from hero;

select sum(ssalary) as sumofmarks from hero;

3) min;

select min(ssalary) from hero;

select min(ssalary) as mimimummarks from hero;

4)max;

select max(ssalary) from hero;

select max(ssalary) as maximummarks from hero;

5) avg;

select avg(ssalary) from hero;

select avg(ssalary) as averagemarks from hero;

SQL----

sql clauses;

1) where clause
select * from villian where amount='20000';

2) distinct

select * from villian distinct amount='20000';

3) from

select * from villian from amount='20000';

4) order by

select * from villian order by name;

5) group by

select name,count(*)from villian group by name;

6)having ;

select count(no),age from grees2 group by age having count(no) <30;

The following SQL statement lists the number of customers in each country.
Only include countries with more than 5 customers:
SELECT COUNT(CustomerID), Country

FROM Customers

GROUP BY Country

HAVING COUNT(CustomerID) < 6;

LIKE: 26-7-2024

1) FIRST LETTER:

Select * from grees2 where sname like “%u”;

IF % positioned in front of c it will be in first letter =”c%”:chintu

If % positioned in last of letter it will execute lasted name=”%u”:chintu

If % is attached with the some of the letters in the name it will execute full as=”%chi”:chintu
a)Select * from grees2 where sname like “c____u”;

b)Select * from grees2 where sname like “c%u”;

29-7-24

Any: any operator works like comparing the value of table to each valiue in the result table

Syntax; Select columns from tablename where columnname=any(sub query);

Eg-Select * from staff where stname = any(select sname from student);

JOINS
INNER JOIN:

INNER join used to return onley those resilts from the table thst matches the specified condition and
hide other row and colomn

Select * from table 1 inner join table2 where condition;

Select * from table1,table 2 where condition;

>select * from staff cross join student on staff.age=student.age;

>select * from staff left outer join student on staff.age=student.age union select * from staff right
outer join student on staff.age=student.age;

CHECK ( ) :

Syntax : create table table name (column


datatype,columname2,datatype, check(condition));

Ex:

Create table student (sno int,sname varchar(20),sage


int,check(sage>18));
Definition;

Check is used to insert the data basedon condition check is


used in creation of table

DEAFULT:

Syntax : create table tablename(columnname


datatype,columnname datatype default value);

Ex:

Create table student(sno int,sname varchar(20) default 0);

Defult value is used to assign default value in place of mall

Union :

Union is used to combine two tables values without duplicates

SYN ;

Select colmnname from tablename2;

2)union all:

It is used to combine two tables values with duplicates also

SYN:

select sname from student union all select sname from staff;

3)intersect :

It is used to combine the both tables based on common values

SYN :

select sname from student intersect select sname from staff;


DATA INTEGRITY :

1)Entity integrity : It specifies that there should be no duplicate rows in table

2) Domain integrity : it enforce valied entries for a given column by restrating the type, the

format, or the range of value


Ex- CHECK()
4) refrention integrity : it specifies that rows can’t be deleted which are used by other records
EX- FOREIGNNKEY
5) User define integrity :it encodes some specific business rules that are declared by users. this rules
are different forms ; entity, domain or refention

STRING FUNCTIONS 05/08/2024

1) ASCII ( ) : select ASCII( 'a' );-- select ascii


2) CHAR_LENGHT ( ) : select char_length ("tarun");
3) CONCAT( ) : select concat ("tarun","lavayna");
4) INSERT ( ) : select insert ('tarun',2,2,'ud');
5) LCASE ( ) : select lcase ('TARUN');
6) LEFT ( ) : select left ('tarun', 3);
7) LENGTH ( ) : select length ('tarun');
8) LOWER ( ) : select lower ('TARUN');
9) LTRIM() : select ltrim (‘ tharun’);
10) POSITION ( ) : select position(‘t’ in ‘tharun’);
11) REPEAT ( ) : select repeat ('tarun',6);
12) REPLACE ( ) : select replace ('tarun','aru','wat');
13) REVERSE ( ) : select reverse ('tarun');
14) RIGHT ( ) select right ('tarun', 3);
15) RTRIM ( ) : select rtrim('tarun ');
16) STRCMP ( ) : select strcmp('tarun','tarun');
17) SUBSTRING ( ) : select substring('tarun',2,4);
18) SUBSTR ( ) : select substr('tarun',2,4);
19) TRIM ( ) :
20) UCASE ( ) : select ucase ('tarun');
21) UPPER ( ) : select upper ('tharun');
MATH FUNCTIONS :

1) ABS : ‘ABSOLUTE VALUE’- select abs (-12.5)


2) AVG:
3) COUNT :select count (column) from tablename-
4) DEGREE : select degrees (27.5); which gives an degrees value
5) CEIL : select ceil (27.89); which gives an upper value
6) FLOOR : select floor (27.89); which gives an lowewr value
7) GRATEST : select greatest(20,40,2000,54545454);which gives
greatest value
8) LEAST : select least(20,40,2000,54545454);which gives lowest
value
9) EXP : Select exp(30); give exponential value
10) LOG : select log (20); shows log

11) LOG 10 :

10)LOG 2 :

12) MAX : select max(salary)from staff;


13) MIN : : select min(salary)from staff;
14) MOD : select mod(10,20);
15) PI : select PI();
16) POWER : select power (2,10);
17) ROUND : select round(20.9);
18) SQRT : select sqrt(64);
19) SUM :select sum(10,20,20);

DATE AND TIME FIUNCTIONS :


1) SELECT DAY : (‘2024-06-2023’); - //23
2) Adddate: select adddate(“2024-06-12”interval 3 day); it will
shift to 3 days xtra .
3) Addtime: select addtime(“2024-06-12”,”00:15:15”)
4) Current-date: select current_date();
5) Current-time: select current_time();
6) Select dayname : (‘2024-06-2023’); - //sunday
7) Select hour : (‘2024-06-2023 04:30 ’); - //9
8) Select current_timestamp ( ); : 2024-06-2023 15:26:12
9) Select quarter (‘2024-06-09’);-//2
10) Select week day (‘2024-06-17’);//2
11) Select week(“2024-09-06”);
12) Select last-day(“2024-08-06”);

You might also like