Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello! Help me with SQL , please! We have following tables from database _ adventureworkslt: CREATE TABLE plan _ status ( quarterid varchar ( 6
Hello! Help me with SQL please!
We have following tables from database adventureworkslt:
CREATE TABLE planstatus
quarterid varchar NOT NULL,
status varchar NOT NULL,
modifieddatetime timestamp DEFAULT CURRENTTIMESTAMP NOT NULL,
author varchar DEFAULT CURRENTUSER NOT NULL,
country varchar NOT NULL,
CONSTRAINT planstatuspk PRIMARY KEY quarterid country
;
CREATE TABLE countrymanagers
username varchar NOT NULL,
country varchar NOT NULL,
CONSTRAINT countrymanagerspk PRIMARY KEY username country
;
CREATE TABLE public.plandata
versionid varchar NOT NULL,
country varchar NOT NULL,
quarterid varchar NOT NULL,
pcid int NOT NULL,
salesamt numeric NULL,
CONSTRAINT planappdatapkey PRIMARY KEY quarterid country, pcid, versionid
;
Write a function in python acceptplanyear quarter, user, pwd The function will copy the modified
data into the actual version of the plan.
The function is expected to select the records from the existent version of plandata table, change the
versionid there and then change the status in the planstatus table when the records in the original
versions P and R respectively meet the following requirements:
Planning quarter quarterid column is equal to combination of year and quarter from the
function's arguments.
Version equals to Pwhich refers to a modified version of the plan
Data status in planstatus table equals to R
The current user has a permission to access the plan data according to the settings in the
countrymanagers table.
Implement these processing steps in the acceptplan function:
Clear the A version of plan data for specific quarter and countries accessible to the current user
Read data available to the current user from the version P and save its copy as the version A
Change the status of the processed from R to A
When updating the status, also save a timestamp in the modifiedtimestamp column.
Thus, after the function is applied, the tables should get their versionid and status updated to A as well
as the author and modifieddatetime columns in planstatus should show the info of who and when made
the latest changes.
Use the developed function to approve the plan of Q on behalf of each manager. Check whether
the data is visible through the vplan view:
The administrator has access to the entire plan
Manager can view the only data heshe is permitted to read and change.
Details on how each column can be populated are shown in the tables below.
Table Rules for changing records in the planstatus table
Field Description Rules
quarterid Key of planning quarter No Changes
country Country of a company No Changes
status Planning data status A
modifieddatetime Time when the record was changed or created currenttimestamp
author User who changed the record currentuser
Table Rules for loading data in the plandata table
Field Description Rules
versionid Version of plan A
country Country of a shop which orders goods Copy from version P
quarterid Key of planning quarter Copy from version P
pcid Product categorys key Copy from version P
salesamt Sales amount before taxes Copy from version P
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started