I am assuming you are using GridDB SQL. Then, you need to use the below 5 Clauses:
a. TIMESTAMP_DIFF function in GridDB - to compare the two timestamps/dates
TIMESTAMP_DIFF(time_unit, timestamp1, timestamp2 [, timezone])
where time_unit can be YEAR | MONTH | DAY | HOUR | MINUTE | SECOND | MILLISECOND
b. TIMESTAMP function - to convert string dates to timestamp in griddb
TIMESTAMP(timestamp_string [, timezone])
c. NOW() function - to get the current date timestamp in griddb
NOW()
d. LIMIT function - to limit the number of records
LIMIT __By-Number__
e. ORDER BY function - to order the number of rows in Ascending or descending order
ORDER BY ASC/DESC
I am getting the experience of the employees by DAY (by comparing it with the current date timestamp), but you can do it for YEAR or MONTH by replacing DAY in the below query. I assume the "DateOfJoining" column is of type VARCHAR in the table, meaning it needs to be converted to Timestamp. So, the final query would look like this:
SELECT Empid, Empname, Salary , TIMESTAMP_DIFF(DAY, NOW(),TIMESTAMP(DateOfJoining)) as exper_by_days from employee order by exper_by_days;
You can limit the number of records by displaying only the top 5 rows with lowest experience using the below query:
SELECT Empid, Empname, Salary , TIMESTAMP_DIFF(DAY, NOW(),TIMESTAMP(DateOfJoining)) as exper_by_days from employee order by exper_by_days LIMIT 5;