Написати SQL запит для FIFO транзакцій
Дані на вході
- Записи про надходження товарів за ціною
- Записи про продаж товарів за ціною
Що, очікується на виході
- Перелік усіх транзакцій з урахуванням собівартості, прибутку та суми залишку після транзакції
Прикріплений файл містить приклад даних та очікуваний результат
- items - таблиця з даними про товари
- id - id товару
- sku - артикул назва товару
- name - назва товару
- documents - таблиця з даними про постачання або продажі.
- id - id документу
- post_at - дата/час проведення документу
- type - тип транзакції. inbound_supply - постачання, а outbound_sales - продаж
- status_id - статус документу. Цікавлять лише зі значенням done
- document_items - товари в документі по к-сть та ціні
- document_id - id документу
- item_id - товару
- qty - кількість
- price_with_discount - остаточна ціна за одиницю
- fifo_transactions - приклад результату, що очікується отримати
- post_at - дата/час транзакції з відповідного документу
- document_id - id документу
- item_id - id товару
- qty_change - зміна кількості. -1 це продаж, а +1 це постачання
- price - ціна за одиницю
- sum - сума транзакції
- profit - прибуток по транзакції. Тільки для продажу. Для постачання очікується NULL
- cost_change - зміна по собівартості
- qty_after - кількість після транзакції
- cost_after - собівартість одиниці після транзакції
- cost_sum_after - сума собівартості після транзакції
Важливо врахувати
- Історичність надходження та продаж на основі post_at
- Усі ідентифікатори в БД мають тип UUID і не можуть бути послідовними
- Швидкодія та оптимізація на даному етапі не цікавить. Важливо тільки, щоб запит повертав коректні результати
- Можемо провести короткий дзвінок і дати відповіді на усі запитання
Applications 1
-
Я правильно понял в documentsСontents(document_item) у Вас в продаже(ссылка на продаж) стоит цена по которой продали?
Там в базе надо делать рефакторинг вначале
-
Current freelance projects in the category Databases & SQL
Power BI
16 USD
The dashboard runs on a Google server, we need to transfer all logic + code Required skills: deployment of ETL processes on a Linux server + working with BigQuery and Postgre There is working code that runs on Google, where the database itself is, we need to transfer it to… Python, Databases & SQL ∙ 3 hours 57 minutes back ∙ 6 proposals |
Need a 1C specialist for refinements and development.I am looking for a 1C specialist for freelance collaboration. I am currently working with a contractor who provides support and maintenance for the 1C system. However, due to the contractor's workload, there is a need for prompt execution of additional tasks, improvements, and… Databases & SQL ∙ 2 days 3 hours back ∙ 11 proposals |
Restoring Instagram after a banOn March 3, 2026, my Instagram was blocked due to a violation of rules. I believe there has been some mistake, as the page was personal with photos and videos of my personal trips. I did not post any comments anywhere. I have sent several appeals. I cannot download my files… Databases & SQL, Web Programming ∙ 2 days 14 hours back ∙ 5 proposals |
Eliminate the issue of incomplete data import from Excel files of Nova Poshta specifications into 1C:
45 USD
Goal: There is a processing in 1C for uploading the specifications of Nova Poshta. For unclear reasons, it has stopped loading some tabular data. We need to find the reason and eliminate the problem of incomplete data import from Excel files of Nova Poshta specifications into… System & Network Administration, Databases & SQL ∙ 5 days 21 hours back ∙ 16 proposals |
Accounting, planning, and sales system for a mushroom farm
603 USD
Here is the complete, final text of the Technical Assignment (TA). It combines all your requirements: 16 chambers, 20 contractors, a schedule by days, accounting for containers, profitability calculation, and a mandatory division into three grades of mushrooms. You can fully… Databases & SQL, Client Management & CRM ∙ 8 days 1 hour back ∙ 59 proposals |