Samruddhi Mungal
Samruddhi Mungal

Reputation: 1

How to select hired year for all employees at Northwinds, a simple query

Q. For all employees at Northwinds, list the first name and last name concatenated together with a blank space in-between, and the YEAR when they were hired.

`SELECT firstname || ' ' || lastname as "Name"

from employees;`

This works to get the concatenation but what to add for the hiring year?

I tried this: -

`SELECT firstname || ' ' || lastname as "Name"
    
 date_part('year', hiredate)
 
from employees;`

This didn't work for me.

Upvotes: 0

Views: 41

Answers (1)

bics siva
bics siva

Reputation: 1

MySQL
--------
SELECT concat(firstname ,' ', lastname) as "Name" FROM employees
where year(date_part) <Year or date_part <hiredate;

PostgreSQL
----------
SELECT CONCAT(firstname, ' ', lastname) AS "Name"
FROM employees
WHERE EXTRACT(YEAR FROM date_part) < Year OR date_part < hiredate;

Upvotes: 0

Related Questions