Select From Employee Users
Select From Employee Users
select *,
row_number() over(partition by user_name order by user_id)as rn
from users order by user_id;
select user_id ,user_name,email
from(
select *,
row_number() over(partition by user_name order by user_id)as rn
from users order by user_id) x
where x.rn > 1
============================
select *from doctors
self join is to join the same table self
select d1.*
from doctors d1
join doctors d2 on d1.id <> d2.id and d1.hospital = d2.hospital and d1.speciality
<> d2.speciality;
========================================
select *,
case when user_name =lead(user_name) over( order by login_id)
and user_name=lead(user_name,2) over( order by login_id)
then user_name
else null
end as repeated_users
from login_details;
select distinct user_name
from(
select *,
case when user_name =lead(user_name) over( order by login_id)
and user_name=lead(user_name,2) over( order by login_id)
then user_name
else null
end as repeated_users
from login_details) x
where x.repeated_users is not null;
===============================================
select *,
case when temperature < 0 --case to compare rows
and lead(temperature) over( order by id) <0
and lead(temperature,2) over( order by id) <0
then 'Yes'
when temperature < 0 --case to compare rows
and lag(temperature) over( order by id) <0
and lead(temperature) over( order by id) <0
then 'Yes'
when temperature < 0 --case to compare rows
and lag(temperature) over( order by id) <0
and lag(temperature,2) over( order by id) <0
then 'Yes'
else null
end flag ---just like return
from weather) x
where x.flag = 'Yes'
==========================
selct month ,account_id, no_o_patients
fom(
select *,
rank() over (partition by month order by no_of patients desc,acount_id) as rnk
select month,account_id ,count(1) as no _of _patients
from(
select to_char(date,'month') as month,account_id,patient_id
from patient_logs) pl
group by month,account_id)x
===============================
mysql-u rama -p
type passwd
===================================================================================
create table test(
test_column
);
alter table test
add another-column varchar(25);
drop to remove
create table bands(
id int not null auto_increment,
name varchar(255) not null,
primarykey(id));
create table albums(
id int not null auto_increment,
namr varcha(255) not null,
release_year int,
band_id int not null,
primary key (id),
foreign key(band_id) references band(id)
);
);
);
=====
select * from bands
select *from bands limit 2;
select distinct name from albums
update albums set release_year=19 where id=1;
select *from albums where release_year < 2000;
select * from albums where name like '%er%' or band_id =2;
select *from albums
where release_year =1984 and band_1;
select *from albums where release_year between 2000 and 2018;
select * from albums where release_year is null;
delete from albums
where id=5;
select *from albums;
select *from bands join albums on band.id= albums.band_id;