Avatar of egovernment
egovernment
Flag for Afghanistan asked on

SQL Statement in Oracle & Access

If I have these tables

Table_A
======
Emp_Id
Emp_Name
Emp_Grade_Id

Open in new window


For example
Emp_Id        Emp_Name         Emp_Grade_Id
333              John Smith          0007
666              Mikel Josef          008

Open in new window


Table_B
======
Emp_Grade_Id
Emp_Grade_Name

Open in new window


For example
Emp_Grade_Id          Emp_Grade_Name
0007                         Manager
008                           System Analysis

Open in new window


Table_C
======
Emp_Id
ALW_DED_Id
Amount

Open in new window


For example
Emp_Id                     ALW_DED_Id            Amount
333                           1000                        500
333                           1001                        50
333                           1002                        30
333                           1003                        15

Open in new window


Table_D
======
ALW_DED_Id
ALW_DED_NAME

Open in new window


For example
ALW_DED_Id            ALW_DED_NAME
1000                        Basic
1001                        Accomadation
1002                        Electrisity
1003                        Water

Open in new window


What is the SQL Statement to display the following: -
Emp_Id     Emp_Name      Emp_Grade_Name   Basic    Accomadation    Elec   Water

Open in new window


In oracle & Access
Microsoft AccessOracle DatabaseSQL

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon
slightwv (䄆 Netminder)

Is there a maximum number of ALW_DED_Id entries for employees in table_C?
egovernment

ASKER
Is there a maximum number of ALW_DED_Id entries for employees in table_C?
4
slightwv (䄆 Netminder)

What version of Access are you using?

Try this for Oracle:

select a.emp_id, a.emp_name,
	b.emp_grade_name,
	max(case when c.alw_ded_id = '1000' then alw_ded_name end) basic,
	max(case when c.alw_ded_id = '1001' then alw_ded_name end) accomadation,
	max(case when c.alw_ded_id = '1002' then alw_ded_name end) electricity,
	max(case when c.alw_ded_id = '1001' then alw_ded_name end) water
from table_a a,
	table_b b,
	table_c c,
	table_d d
where a.emp_grade_id=b.emp_grade_id and 
	a.emp_id=c.emp_id and
	c.alw_ded_id=d.alw_ded_id
group by a.emp_id, a.emp_name, b.emp_grade_name
/

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
egovernment

ASKER
What version of Access are you using?
Access 2003
ASKER CERTIFIED SOLUTION
slightwv (䄆 Netminder)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.