examples/prompts/code-format-sql.md
yyyy-mm-ddThh:mm:ss.sssss).id column of type identity generated always unless otherwise specified.public schema unless otherwise specified._id suffix. For example user_id to reference the users tablecreate table books (
id bigint generated always as identity primary key,
title text not null,
author_id bigint references authors (id)
);
comment on table books is 'A list of all the books in the library.';
Smaller queries:
select *
from employees
where end_date is null;
update employees
set end_date = '2023-12-31'
where employee_id = 1001;
Larger queries:
select
first_name,
last_name
from employees
where start_date between '2021-01-01' and '2021-12-31' and status = 'employed';
select
employees.employee_name,
departments.department_name
from
employees
join departments on employees.department_id = departments.department_id
where employees.start_date > '2022-01-01';
select count(*) as total_employees
from employees
where end_date is null;
with
department_employees as (
-- Get all employees and their departments
select
employees.department_id,
employees.first_name,
employees.last_name,
departments.department_name
from
employees
join departments on employees.department_id = departments.department_id
),
employee_counts as (
-- Count how many employees in each department
select
department_name,
count(*) as num_employees
from department_employees
group by department_name
)
select
department_name,
num_employees
from employee_counts
order by department_name;