You are on page 1of 6

Assignment 6

Reyden Harris

This command creates the keyspace ‘testice6’

a. We can describe our keyspaces with ‘desc keyspaces’

b. With the USE command we can select which keyspace we would like to work in.

c. We need to create our employees table so we can import the data in the next step.

d. After successful creation of table, we need to import our employee_entries.csv file. We do so with the below command.

e. To validate our Import, we need to run ‘select * from employees;’ to pull all the records on the table.
1. List the empID, department, hired-date, and salary of employees such that their salary is between 15000 and 70000 inclusive from the employee table.
We select which attributes we’d like to display, then with the from clause we can filter results with our salary field with defined parameters.

2. List the last name starting with letter ‘G’, manager id of the employees who are from the engineering department.
Here we need to use the parameters department = engineering and lastname starts with G.

I ran into and error regarding index not being set up for this column.

So I set up a custom INDEX for this column

Then we can re-run our query and return the correct results.
3. List the name, job, salary of every employee joined after 2009.
We use the select statement to list the name, title, and salary of the employees that have a start date after 2009 by using the where clause to establish a filter that uses the hired date column.

4. Display employees’last name, hired-date and salary values of those


employees who are team leads and from the sales department from the EMP table using SELECT statement.

5 Add a record to employee table with employee whose last name is Vince and works in marketing department as software developer with salary 65000 and hired on Nov 20th, 2000 having
managerid . 5
Using the INSERT statement we define what columns we are inserting in the first set of parentheses, after the VALUES clause we define the data points in the second set of parentheses.
6. Modify the salary of Stevens to 52500 in employee table.
Here is our baseline data, particularly Stevens with a salary of 50,000

Due to Employee ID being our Primary key any update statements need to be including the primary key, we need to validate it
Now we have stevens employee iD we can run the update statement to set stevens new salary to 52500.

\
7. Display top 3 employees working for the greatest number of years in the company.
I had a few errors to workout in this problem, I had to set the clustering order to years_with_company when creating table. I had to drop table and re-create. (see step C)
Then I had to make sure the query includes the partitioning key and an Equality or inequality function.
Once I had this figured, I was able use the order by clause and desc to sort the results by years_with_company

8. Display the count ofemployees who joined in January along with their details.
Here we need to create a function for month, Cassandra does not have a native MONTH function so we need to create one.
First we need to enable user-defined functions in the YAML file.

Then we will need to create our function to extract the month from our date format ‘YYYY-MM-DD’

I used the substring function to pull the results of positions starting at 5 and ending at 7.
9. For the above query use an alias word for count as “NoOfEmps”.

10. Find the average number of years employees have worked in the company.

You might also like