Jeswanth
Jeswanth

Reputation: 197

How to get non-nullable data in columns

Please refer below details

Current output:

EmpID   EmployeeDailyFee  EmployeeMonthlyFee  CompanyDailyFee  CompanyMonthlyFee
12      NULL              150                 NULL             NULL
12      120               NULL                NULL             NULL

Expected output:

EmpID   EmployeeDailyFee  EmployeeMonthlyFee  CompanyDailyFee  CompanyMonthlyFee
12      120               150                 NULL             NULL

Please let me know your suggestions

Upvotes: 0

Views: 60

Answers (1)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

If you only get one non-null value in each column for each employee, you could try the following:

SELECT EmpID ,
       MAX(EmployeeDailyFee) AS EmployeeDailyFee,
       MAX(EmployeeMonthlyFee) AS EmployeeMonthlyFee, 
       MAX(CompanyDailyFee) AS CompanyDailyFee, 
       MAX(CompanyMonthlyFee) AS CompanyMonthlyFee
FROM Employees
GROUP BY EmpID 

Upvotes: 2

Related Questions