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

SQL queryFT2

Uploaded by

RizkyMulyadi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

SQL queryFT2

Uploaded by

RizkyMulyadi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

create table m_bank (

id BIGINT primary key not null,


name varchar(100),
va_code varchar(10),
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean not null
);

drop table m_bank ;

create sequence m_bank_id_seq;


alter sequence m_bank_id_seq owned by m_bank.id;
alter table m_bank alter column id set default nextval('m_bank_id_seq');

select * from m_bank order by id;

select * from m_bank where is_delete = false order by id;

alter table m_bank add constraint fk_bank_create_by foreign key (created_by)


references m_user(id);
alter table m_bank add constraint fk_bank_modify_by foreign key (modified_by)
references m_user(id);

UPDATE m_bank SET is_delete = true,


modified_by = '14',
modified_on = now()
WHERE id=38;

SELECT count(*) as count from m_bank where is_delete = false and (name ilike
'Bank Anteng' OR va_code='3014');

SELECT count(*) as count from m_bank where is_delete = false and (name ilike 'Bank
Anteng');

SELECT count(*) as count from m_bank where is_delete = false and (va_code='3014');

SELECT COUNT(*) as count FROM m_bank WHERE is_delete = false and(name = 'Bank
Anteng' OR va_code = '3014')AND id != 2;

SELECT COUNT(*) as count FROM m_bank WHERE is_delete = false and((name ilike 'Bank
Anteng')AND id != 41);

SELECT COUNT(*) as count FROM m_bank WHERE is_delete = false and((va_code =


'3014')AND id != 41);

/----------------------------------------------------------------------------------
------/

create table m_blood_group(


id bigint primary key generated always as identity not null,
code varchar(5),
description varchar(255),
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/----------------------------/

create table m_customer(


id bigint primary key generated always as identity not null,
biodata_id BIGINT,
dob date,
gender varchar (1),
blood_group_id bigint not null,
rhesus_type varchar (5),
height decimal,
weight decimal,
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/-----------------------------/

create table m_customer_member(


id bigint primary key generated always as identity not null,
parent_biodata_id bigint,
customer_id bigint,
customer_relation_id bigint,
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/-------------------------------------------------------/
create table m_customer_relation(
id bigint primary key generated always as identity not null,
name varchar(50),
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/----------------------------------------------------------/

create table m_user(


id bigint primary key generated always as identity not null,
biodata_id bigint not null,
role_id bigint not null,
email varchar(100),
password varchar(200),
login_attempt int,
is_locked boolean,
last_login date,
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/-----------------------------------------------------------------/

create table m_role(


id bigint primary key generated always as identity not null,
name varchar(20),
code varchar(20),
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

/------------------------------------------------------------------/

create table m_biodata(


id bigint primary key generated always as identity not null,
fullname varchar(255),
mobile_phone varchar(15),
image bytea,
image_path varchar(255),
created_by bigint not null,
created_on date not null,
modified_by bigint,
modified_on date,
deleted_by bigint,
deleted_on date,
is_delete boolean default false not null
);

SELECT count(*) as count from m_bank where name like


'%Bank ABC%' OR va_code='3013';

/------------------------------------------------------------------------/

alter table m_bank add constraint fk_bank_create_by foreign key (created_by)


references m_user(id);
alter table m_bank add constraint fk_bank_modify_by foreign key (modified_by)
references m_user(id);
alter table m_biodata add constraint fk_biodata_create_by foreign key (created_by)
references m_user(id);
alter table m_biodata add constraint fk_biodata_modify_by foreign key
(modified_by) references m_user(id);
alter table m_role add constraint fk_role_create_by foreign key (created_by)
references m_user(id);
alter table m_role add constraint fk_role_modify_by foreign key (modified_by)
references m_user(id);
alter table m_user add constraint fk_user_create_by foreign key (created_by)
references m_user(id);
alter table m_user add constraint fk_user_modify_by foreign key (modified_by)
references m_user(id);
alter table m_customer add constraint fk_customer_create_by foreign key
(created_by) references m_user(id);
alter table m_customer add constraint fk_customer_modify_by foreign key
(modified_by) references m_user(id);
alter table m_customer_relation add constraint fk_customer_r_create_by foreign key
(created_by) references m_user(id);
alter table m_customer_relation add constraint fk_customer_r_modify_by foreign key
(modified_by) references m_user(id);
alter table m_customer_member add constraint fk_customer_m_create_by foreign key
(created_by) references m_user(id);
alter table m_customer_member add constraint fk_customer_m_modify_by foreign key
(modified_by) references m_user(id);
alter table m_blood_group add constraint fk_blood_create_by foreign key
(created_by) references m_user(id);
alter table m_blood_group add constraint fk_blood_modify_by foreign key
(modified_by) references m_user(id);

alter table m_biodata drop constraint fk_biodata_create_by;


alter table m_biodata drop constraint fk_biodata_modify_by;
alter table m_user drop constraint fk_user_create_by;
alter table m_user drop constraint fk_user_modify_by;
alter table m_role drop constraint fk_role_create_by;
alter table m_role drop constraint fk_role_modify_by;
alter table m_bank drop constraint fk_bank_create_by;
alter table m_bank drop constraint fk_bank_modify_by;
alter table m_customer drop constraint fk_customer_create_by;
alter table m_customer drop constraint fk_customer_modify_by;
alter table m_customer_relation drop constraint fk_customer_r_create_by;
alter table m_customer_relation drop constraint fk_customer_r_modify_by;
alter table m_customer_member drop constraint fk_customer_m_create_by;
alter table m_customer_member drop constraint fk_customer_m_modify_by;
alter table m_blood_group drop constraint fk_blood_create_by;
alter table m_blood_group drop constraint fk_blood_modify_by;

alter table m_customer_member drop constraint fk_customer_m_parent;

alter table m_customer_member add constraint fk_customer_m_parent foreign key


(parent_biodata_id) references m_biodata(id);
alter table m_customer_member add constraint fk_customer_m_customer foreign key
(customer_id) references m_customer(id);
alter table m_customer_member add constraint fk_customer_m_customer_relation
foreign key (customer_relation_id) references m_customer_relation(id);
alter table m_customer add constraint fk_customer_biodata foreign key (biodata_id)
references m_biodata(id);
alter table m_customer add constraint fk_customer_blood foreign key
(blood_group_id) references m_blood_group(id);
alter table m_user add constraint fk_user_role foreign key (role_id) references
m_role(id);
alter table m_user add constraint fk_user_biodata foreign key (biodata_id)
references m_biodata(id);

alter table m_customer_member drop constraint fk_customer_m_parent ;


alter table m_customer_member drop constraint fk_customer_m_customer;
alter table m_customer_member drop constraint fk_customer_m_customer_relation ;
alter table m_customer drop constraint fk_customer_biodata;
alter table m_customer drop constraint fk_customer_blood;
alter table m_user drop constraint fk_user_role;
alter table m_user drop constraint fk_user_biodata;

/-----------------------------------------------------------------------/

select * from m_customer_member mcm ;


select * from m_customer_relation mcr ;
select * from m_customer mc ;

select * from m_bank mb ;


select * from m_blood_group mbg ;
select * from m_user mu ;
select * from m_role mr ;
select * from m_biodata mb order by id;

/------------------------------------------------------------------------/
select c.*,b.fullname,cr."name",extract (year from now()) - extract (year from
c.dob) as umur
from m_customer c
join m_biodata b
on c.biodata_id = b.id
join m_customer_member cm
on cm.customer_id = c.id
join m_customer_relation cr
on cr.id = cm.customer_relation_id
join m_user u
on u.id = cm.parent_biodata_id
order by c.id;

select c.*,b.fullname,cr."name",extract (year from now()) - extract (year from


c.dob) as umur
from m_customer c
join m_biodata b
on c.biodata_id = b.id
join m_customer_member cm
on cm.customer_id = c.id
join m_customer_relation cr
on cr.id = cm.customer_relation_id
join m_user u
on u.id = cm.parent_biodata_id
order by b.fullname;

select c.*,b.fullname,cr."name",extract (year from now()) - extract (year from


c.dob) as umur
from m_customer c
join m_biodata b
on c.biodata_id = b.id
join m_customer_member cm
on cm.customer_id = c.id
join m_customer_relation cr
on cr.id = cm.customer_relation_id
join m_user u
on u.id = cm.parent_biodata_id
order by c.dob;

select c.*,b.fullname,cr."name",extract (year from now()) - extract (year from


c.dob) as umur
from m_customer c
join m_biodata b
on c.biodata_id = b.id
join m_customer_member cm
on cm.customer_id = c.id
join m_customer_relation cr
on cr.id = cm.customer_relation_id
join m_user u
on u.id = cm.parent_biodata_id
order by c.dob desc;

with inserted_orderheader as (insert into orderheaders(reference, amount,


is_active, create_by, create_date)
values('SLS-0923-0001',50000,true,'admin1',now())
returning id) insert into orderdetails (header_id,
product_id, quantity, price, is_active, create_by, create_date)
values ((select id from inserted_orderheader),5,
2,5000,true,
'admin1',now());

select extract (year from now()) - extract (year from dob) as umur from m_customer;

select c.*,b.fullname,cr."name",extract (year from now()) - extract (year from


c.dob) as umur
from m_customer c
join m_biodata b
on c.biodata_id = b.id
join m_customer_member cm
on cm.customer_id = c.id
join m_customer_relation cr
on cr.id = cm.customer_relation_id
join m_user u
on u.id = cm.parent_biodata_id
where UPPER(b.fullname) LIKE UPPER ('%%') AND c.is_delete = false
order by c.id
limit 5
offset 1;

select mc.*,mb.fullname,mcr."name",extract (year from now()) - extract (year


from mc.dob) as umur
from m_customer mc
join m_customer_member mcm
on mc.id = mcm.customer_id
join m_biodata mb
on mb.id = mc.biodata_id
join m_customer_relation mcr
on mcr.id = mcm.customer_relation_id
order by mb.fullname;

select mc.id, mb.fullname, extract (year from now()) - extract (year from mc.dob)
as umur, mc.gender, mbg.code, mc.rhesus_type, mc.height, mc.weight, mcr.name
from m_biodata mb
join m_customer mc
on mb.id = mc.biodata_id
join m_blood_group mbg
on mbg.id = mc.blood_group_id
join m_customer_member mcm
on mcm.customer_id = mc.id
join m_customer_relation mcr
on mcr.id = mcm.customer_relation_id
WHERE mc.is_delete = false;

/----------------------------------------------------------------------------------
--------------------/

create table m_education_level (


id BIGINT primary key generated always as identity not null,
name varchar(10),
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

select * from m_education_level;

alter table m_education_level add constraint fk_jp_create_by foreign key


(created_by) references m_user(id);
alter table m_education_level add constraint fk_jp_modify_by foreign key
(modified_by) references m_user(id);

/----------------------------------------------SPRINT 2----BUAT
JANJI------------------------------------------------/

create table t_appointment (


id BIGINT primary key generated always as identity not null,
customer_id bigint,
doctor_office_id bigint,
doctor_office_schedule_id bigint,
doctor_office_treatment_id bigint,
appointment_date date,
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

/----------------------------FASKES--------------------------------/

create table t_doctor_office (


id BIGINT primary key generated always as identity not null,
doctor_id bigint,
medical_facility_id bigint,
specialization varchar(100),
start_date date,
end_date date,
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);
create table m_medical_facility (
id BIGINT primary key generated always as identity not null,
name varchar(50),
medical_facility_category_id bigint,
location_id bigint,
full_address text,
email varchar(100),
phone_code varchar(10),
phone varchar(15),
fax varchar(15),
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

/-----------------------------------------
Date---------------------------------------------/

create table t_doctor_office_schedule (


id BIGINT primary key generated always as identity not null,
doctor_id bigint,
medical_facility_schedule_id bigint,
slot int,
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

create table m_medical_facility_schedule (


id BIGINT primary key generated always as identity not null,
medical_facility_id bigint,
day varchar(10),
time_schedule_start varchar(10),
time_schedule_end varchar(10),
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);
/----------------------------------------------------------------------------------
-----------/

create table t_doctor_office_treatment (


id BIGINT primary key generated always as identity not null,
doctor_treatment_id bigint,
doctor_office_id bigint,
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

create table t_doctor_treatment (


id BIGINT primary key generated always as identity not null,
doctor_id bigint,
name varchar(50),
created_by BIGINT not null,
created_on date not null,
modified_by BIGINT,
modified_on date,
deleted_by BIGINT,
deleted_on date,
is_delete boolean default false not null
);

/-------/

alter table t_appointment add constraint fk_cm_id foreign key (customer_id)


references m_customer(id);
alter table t_appointment add constraint fk_tdo_id foreign key (doctor_office_id)
references t_doctor_office(id);
alter table t_appointment add constraint fk_tdos_id foreign key
(doctor_office_schedule_id) references t_doctor_office_schedule(id);
alter table t_appointment add constraint fk_tdot_id foreign key
(doctor_office_treatment_id) references t_doctor_office_treatment(id);
alter table t_doctor_office_treatment add constraint fk_tdt_id foreign key
(doctor_treatment_id) references t_doctor_treatment(id);
alter table t_doctor_office add constraint fk_mf_id foreign key
(medical_facility_id) references m_medical_facility(id);
alter table t_doctor_office_schedule add constraint fk_mfs_id foreign key
(medical_facility_schedule_id) references m_medical_facility_schedule(id);

alter table t_doctor_office add constraint fk_tdo_create_by foreign key


(created_by) references m_user(id);
alter table t_doctor_office add constraint fk_tdo_modify_by foreign key
(modified_by) references m_user(id);
alter table m_medical_facility add constraint fk_mmf_create_by foreign key
(created_by) references m_user(id);
alter table m_medical_facility add constraint fk_mmf_modify_by foreign key
(modified_by) references m_user(id);
alter table t_doctor_office_schedule add constraint fk_tdos_create_by foreign key
(created_by) references m_user(id);
alter table t_doctor_office_schedule add constraint fk_tdos_modify_by foreign key
(modified_by) references m_user(id);
alter table t_appointment add constraint fk_ta_create_by foreign key (created_by)
references m_user(id);
alter table t_appointment add constraint fk_ta_modify_by foreign key (modified_by)
references m_user(id);
alter table t_doctor_treatment add constraint fk_tdt_create_by foreign key
(created_by) references m_user(id);
alter table t_doctor_treatment add constraint fk_tdt_modify_by foreign key
(modified_by) references m_user(id);
alter table t_doctor_office_treatment add constraint fk_tdot_create_by foreign key
(created_by) references m_user(id);
alter table t_doctor_office_treatment add constraint fk_tdot_modify_by foreign key
(modified_by) references m_user(id);
alter table m_medical_facility_schedule add constraint fk_mmfs_create_by foreign
key (created_by) references m_user(id);
alter table m_medical_facility_schedule add constraint fk_mmfs_modify_by foreign
key (modified_by) references m_user(id);

You might also like