Question

PLEASE NOTE BEFORE YOU ANSWER. THIS IS NOT MYSQL, IT IS MONGODB. IF YOU DO NOT...

PLEASE NOTE BEFORE YOU ANSWER. THIS IS NOT MYSQL, IT IS MONGODB. IF YOU DO NOT KNOW MANGODB, PLEASE DO NOT ANSWER THIS QUESTION. LEAVE IT FOR SOMEONE WHO KNOWS IT.

PART 1

Create a collection that will hold the data in avgprice kwh state.json. This .json file contains the annual data from 1990-2012 on the average energy price per kilowatt hour (KwH) by state and provider type. Implement the following queries:

1. Print each document that has Oklahoma as state, order the result by year in descending order.

2. Print the average residential, commercial, industrial, and transportation price for the state of Texas from the year 1990-2012.

PART 1

Create collections to hold the data in Masters.json, which contains a master list of players and their information, Teams.json (Teams data), Batting.json (batting statistics) and Salaries.json (salary statistics). Load these files into mongodb and implement the following queries:

1. List of top 50 players by highest number of home runs in the 2012 season. List the players by Player ID, First Name and Last Name, number of home runs and season year.

2. List average salaries for each team in 2012. List the teams by Team ID, League ID, Team Name, and average salary amount in descending order.

NOTE: You should use the aggregate() method to answer the questions where required. I just need the query statements. THIS IS IN MONGO DB. if you need more clarifications, ask me on the comments.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PART 1

assuming state is collection name
and db as database
state_name is key having state names like texas


1. Print each document that has Oklahoma as state, order the result by year in descending order.


db.state.find( { state_name: "Oklahoma" } ).sort( { year: -1 } )

2. Print the average residential, commercial, industrial, and transportation price for the state of Texas from the year 1990-2012.


db.state.aggregate(
[
{ $match: { state_name: "Texas" , year: { $lte: 2012 , $gte : 1990}} },
{
$group:
{
_id: "$state_name",
avg_residential: { $avg: "$residential" },
avg_commercial: { $avg: "$commercial" }
avg_industrial: { $avg: "$industrial" }
avg_transportation: { $avg: "$transportation" }
}
}
]
)

PART 2

assuming batting collection having all data related each player.

1. List of top 50 players by highest number of home runs in the 2012 season. List the players by Player ID, First Name and Last Name, number of home runs and season year.

db.batting.find( { year: "2012" } , { player_id: 1, first_name: 1, last_name: 1, home_runs: 1, season_year: 1 } ).sort( { runs: 1 } ).limit(50)

2. List average salaries for each team in 2012. List the teams by Team ID, League ID, Team Name, and average salary amount in descending order.

db.salaries.aggregate(
[
{ $match: { season_year: "2012"} },
{
$group:
{
_id: "$team_id, $",
avg_salary: { $avg: "$salary" }
}
},
   {$sort: {avg_salary: -1}},
   { $project : { team_id : 1 , leage_id : 1 , team_name : 1 , avg_salary : 1    } }
]
)

Add a comment
Know the answer?
Add Answer to:
PLEASE NOTE BEFORE YOU ANSWER. THIS IS NOT MYSQL, IT IS MONGODB. IF YOU DO NOT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Create a table that will hold the data in avgprice kwh state.csv. This .csv file...

    1. Create a table that will hold the data in avgprice kwh state.csv. This .csv file contains the annual data from 1990-2012 on the average energy price per kilowatt hour (KwH) by state and provider type. Implement the following queries: • Print each row that has Tennessee as state, order the result by year in descending order. • Print the average residential, commercial, industrial, and transportation price for the state of Texas from the year 1990-2012. 2. Create the tables...

  • Hi i need help to answer all the questions please can someone help me thank you. I need to create it in mongodb Perform the following tasks using MongoDB queries: a. List alphabetically only the fir...

    Hi i need help to answer all the questions please can someone help me thank you. I need to create it in mongodb Perform the following tasks using MongoDB queries: a. List alphabetically only the first 20 names of companies founded after the year 2010. b. List only the first 20 names of companies with offices either in California or Texas, ordered by the number of employees and sorted largest to smallest. 3. Perform the following tasks using the MongoDB...

  • Could someone please help me write this in Python? If time allows, it you could include...

    Could someone please help me write this in Python? If time allows, it you could include comments for your logic that would be of great help. This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA women's basketball teams and compute from this the win ratio for each team as well as the conference(s) with the highest average win ratio. Background Whether it's football, basketball, lacrosse, or any other number of...

  • Please answer CLEARLY and LEGIBLE Relational Algebra The local city youth league needs a database system...

    Please answer CLEARLY and LEGIBLE Relational Algebra The local city youth league needs a database system to help track children who sign up to play soccer. Data needs to be kept on each team, the children who will play on each team, and their parents. Also, data needs to be kept on the coaches for each team. Each team is given an ID and Team name. Each player and each parent are given an ID when they sign up. Each...

  • You are building a system to keep track of matches played by a soccer team. You...

    You are building a system to keep track of matches played by a soccer team. You need to create a class to represent your matches. Call this class Soccer Match. The class will have the following data fields and methods: • A Date data field called startTime to register the date and time for the start of the match. • A Date data field called endTime to register the date and time for the end of the match. A String...

  • Can you please write the MySQL Query sentences for the following items below? For example: SELECT...

    Can you please write the MySQL Query sentences for the following items below? For example: SELECT * FROM employees; Generate a list of salespeople sorted descending by hire date. Show the ID, first name, last name, hire date, and salary for each salesperson. Generate a list of customers whose last name begins with the letter “M.” Show the first and last names of these customers. Sort the list of customers descending by last name. C. Generate a list of customers...

  • Given the following relational schema, write queries in SQL to answer the English questions. The Access...

    Given the following relational schema, write queries in SQL to answer the English questions. The Access Database for the schema is available, as is a DDL file. It is also available on the MySQL server. You must only submit the SQL for your answers. You can get your answers without using a DBMS or by using Access or MySQL. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid:...

  • Due to your experience in designing the database for the "Legendary League" game, you have been...

    Due to your experience in designing the database for the "Legendary League" game, you have been asked to design the ER diagram for a bigger database to manage the events for the "Legendary League" eSports Oceanic Championship (OC). The requirements are as follows: Registered teams compete in the OC. Each team has a name, and a number of team members. A team also maintains a rank throughout the OC, reflecting how well it is doing in the championship. Team members...

  • please solve this problem using excel and show steps please D. and the standard deviation of...

    please solve this problem using excel and show steps please D. and the standard deviation of this distribution. 71. FILE Refer to the Baseball 2016 data. Compute the mean number of home runs per game. To do this, first find the mean number of home runs per team for 2016. Next, divide this value by 162 (a season comprises 162 games). Then multiply by 2 because there are two teams in each game. Use the Poisson distribution to estimate the...

  • Someone please answer all of these. I need these badly. The submission date is knocking at...

    Someone please answer all of these. I need these badly. The submission date is knocking at the door. Experiment 1: SQL data definition and data insertion 46 hours) 1. CREATE TABLE. The database schema consists of the three relations, whose schemas are: S (Spa, Sname. Sgender, Sage, Sdert? // students(SID, name, gender, age, department) SC (Spa, Cne. Grade) //Course(SID, CID, grade) C (One Cname Crno. Ceredit) l/courses (CID, course name, prerequisite courses, credit) 2. DROP TABLE, ALTER TABLE, CREATE INDEX,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT