SQL Select Statement Queries with examples like distinct,count,hiredate, like,in, null, concat etc

Опубликовано: 04 Январь 2024
на канале: Technology with Kiran
131
6

Select statements:
===============
select * from employees;
select employee_id,first_name,email,hire_date,salary,department_id from employees;
--column alias
select employee_id as emp_id,first_name,email,hire_date,salary,department_id from employees;
select employee_id emp_id,first_name,email,hire_date,salary,department_id from employees;
select employee_id emp_id,first_name,email,hire_date salary,department_id from employees;
-- column concatenation
select employee_id ,first_name,last_name,concat(first_name,last_name),email,
hire_date salary,department_id from employees;
select employee_id ,first_name,last_name,concat(first_name,last_name) full_name,email,
hire_date ,salary,department_id from employees;
select employee_id ,first_name,last_name,concat(first_name,' ',last_name) full_name,email,
hire_date ,salary,department_id from employees;
--ORA-00909: invalid number of arguments
select employee_id ,first_name,last_name,concat(concat(first_name,' '),last_name) full_name,email,
hire_date ,salary,department_id from employees;




-- alternate way - pipe
select employee_id emp_id,first_name,last_name,first_name||' '||last_name full_name,email,
hire_date, salary,department_id from employees;
-- column calculation
select employee_id,first_name,email,hire_date,salary,salary+1000 new_salary,department_id from
employees;
select employee_id,first_name,email,hire_date,salary,salary*12 annual_salary,department_id from
employees;
-- unique department_id
select department_id from employees;
select count(department_id) from employees;
select distinct department_id from employees;
select count(distinct department_id) from employees;
select count(*) from (
select distinct department_id,job_id from employees);
-- where clause
select * from employees where salary greaterthan10000;
select * from employees where salary Lessthan3000;
select * from employees where salary greaterthan5000 and salary Lessthan7000;
select * from employees where salary greaterthan=5000 and salary Lessthan=7000;
select * from employees where salary between 5000 and 7000;




select * from employees where salary not between 5000 and 7000;
select * from employees where department_id=30;
select * from employees where department_id=30,60,90;
-- ORA-00933: SQL command not properly ended
select * from employees where department_id IN (30,60,90);
select * from employees where department_id NOT IN (30,50,80);
select * from employees where department_id=80 AND salary greaterthan10000;
select * from employees where department_id=60 OR salary greaterthan15000;
select * from employees where department_id=60 OR (department_id=80 AND salary greaterthan10000);
select * from employees where rownum Lessthan=5;
select * from employees where rownum =5; -- Wrong
select * from employees where rownum greaterthan 5; -- wrong
select rownum,rowid,employee_id,first_name from employees;
select rownum,rowid,* from employees; --ORA-00936: missing expression
select rownum,rowid,e.* from employees e;
select * from employees where commission_pct is null;
select * from employees where commission_pct is not null;
select count(*) from employees;


Смотрите видео SQL Select Statement Queries with examples like distinct,count,hiredate, like,in, null, concat etc онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Technology with Kiran 04 Январь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 131 раз и оно понравилось 6 людям.