Generation

text to sql syntaxThu, 10 Nov 2022

A company stores data about its employees in two tables, employees and positions, with the following structure: create table employees ( id integer not null unique, name varchar(30) not null, age integer not null, salary integer not null ); create table positions ( id integer not null unique, department_name varchar(30) not null, employee_id integer not null unique, position_name varchar(30) not null ); Each record in the table employees represents a single employee and consists of the following data: id, name, age and salary. Each record in the table positions represents the position description of a single employee and consists of the following data: id, department_name, employee_id and position_name. Write an SQL query that calculates the average salary of all employees who are working in a Software Engineer position and are at most 30 years old. If there are no such employees then the answer should be NULL..

SELECT AVG(salary) FROM employees e JOIN positions p ON e.id=p.employee_id WHERE position_name="Software Engineer" AND age<=30;

Want to kickstart your project?Use the new AI Studio to create your code