0% found this document useful (0 votes)
20 views

Task 03

The document provides instructions for completing 6 data analysis tasks using data from the task_data2023_11_07.txt file on the Platon platform. The tasks include uploading the data, modifying the structure to add a primary key and age field, calculating ages, finding oldest and youngest records, calculating age group counts, and copying the oldest records to another table. It also provides SQL examples for working with dates, like calculating differences and extracting parts. The document should be saved as a TXT file on the Platon platform as the solution.

Uploaded by

princessoke141
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Task 03

The document provides instructions for completing 6 data analysis tasks using data from the task_data2023_11_07.txt file on the Platon platform. The tasks include uploading the data, modifying the structure to add a primary key and age field, calculating ages, finding oldest and youngest records, calculating age group counts, and copying the oldest records to another table. It also provides SQL examples for working with dates, like calculating differences and extracting parts. The document should be saved as a TXT file on the Platon platform as the solution.

Uploaded by

princessoke141
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2023-11-07&2023-11-09

Task
1. Upload data to your database (task_data2023_11_07.txt Platon platform)
2. Modify the structure
• Create a primary key
• Add an age field
3. Calculate the age of the people and enter the age in the field
4. Find the oldest and youngest person
5. Calculate the number of people in each age group
6. Copy the oldest 10 people to the OLD_EMPLOYEE table
If you can't do it, write why
Save the script in a file with the TXT extension and place it on the Platon platform (Solution_3)
Don't send email solutions!!!
HELP
YEAR ( date ), MONTH ( date ), DAY ( date )

SELECT YEAR ( '2013-02-12' ) as year,


MONTH( '2013-02-12' ) as month,
DAY ( '2013-02-12' ) as day

SELECT SYSDATETIME(),
SYSDATETIMEOFFSET(),
GETDATE(),
GETUTCDATE()

DATEADD (date_part , value , input_date )


This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that
modified value.
date_part abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms
microsecond mcs
nanosecond ns
• date_part is the part of date to which the DATEADD() function will add the value.
• value is an integer number to be added to the date_part of the input_date. If the value evaluates to a decimal or float, the function
DATEADD() will truncate the decimal fraction part. It will not round the number in this case.
• input_date is a literal date value or an expression which can resolve to a value of type DATE, DATETIME,
DATETIMEOFFSET, DATETIME2, SMALLATETIME, or TIME
DATEADD ( datepart, no, date ) –datepart (day, dd, d), (years,yy,yyyy), (month,mm,m), (minute,mi,n) .
This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that
modified value.
SELECT DATEADD ( dd,-DAY( GETDATE()-1 ), GETDATE() ) as FirstDayCurrMonth,
DATEADD ( dd,-DAY( GETDATE() ), GETDATE() ) as LastDayPrevMonth
select dateadd(dd,1,getdate())
DATEDIFF(interval, date1, date2)
This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and
enddate.
Parameter
interval
year, yyyy, yy = Year
quarter, qq, q = Quarter
month, mm, m = month
dayofyear = Day of the year
day, dy, y = Day
week, ww, wk = Week
weekday, dw, w = Weekday
hour, hh = hour
minute, mi, n = Minute
second, ss, s = Second
millisecond, ms = Millisecond
SELECT FirstName, LastName, BirthDate,
DATEDIFF ( yy , BirthDate , GETDATE() ) as Age
FROM dbo.Employee

1
2023-11-07&2023-11-09

DATEPART( datepart, date )

SELECT DATEPART( yy, GETDATE() ) as CurrentYear,


DATEPART( mm, GETDATE() ) as CurrentMonth,
DATEPART( dd, GETDATE() ) as CurrentDay,
DATEPART( ww, GETDATE() ) as CurrentWeek

DATENAME ( datepart, date )

SELECT DATENAME(dw, GETDATE() ) as Day_of_week,


DATENAME(mm, GETDATE() ) as month

SQL - Creating a Table from an Existing Table


A copy of an existing table can be created using a combination of the CREATE TABLE statement and the
SELECT statement. The new table has the same column definitions. All columns or specific columns can be
selected. When you will create a new table using the existing table, the new table would be populated using the
existing values in the old table.
Syntax
The basic syntax for creating a table from another table is as follows:
SELECT column1, column2 ....
INTO [dbo].[new]
FROM [dbo].[old]

You might also like