SQL Queries for Student and Sales Data
SQL Queries for Student and Sales Data
The SQL query is: `SELECT sname, snum FROM salespeople WHERE snum IN (SELECT snum FROM customer GROUP BY snum HAVING COUNT(*) > 1);`. This reveals that salesperson 'Peel' (snum 1001) handles more than one customer, indicating a greater customer network.
The query to display all customers with ratings above San Jose's average is: `SELECT cname FROM customer WHERE rating > (SELECT AVG(rating) FROM customer WHERE city='San Jose');`. Based on the dataset, the customers 'Cisneros' and 'Grass' have ratings above the average rating in San Jose.
Use the query: `SELECT city, MAX(marks) AS top_score FROM student GROUP BY city ORDER BY city;`. The output will show 'Hyderabad' with 95, 'Pune' with 77, and 'bglr' with 87 as the top scores in each city.
The SQL query to find the best city in education based on student scores is: `SELECT city, AVG(marks) AS "avg score" FROM student GROUP BY city ORDER BY "avg score" DESC LIMIT 1;`. Based on the dataset, Hyderabad would be identified as the best city in education due to its highest average score.
To find the salesperson with the highest customer rating, you can use the following SQL query: `SELECT sname FROM salespeople WHERE snum IN (SELECT snum FROM customer GROUP BY snum ORDER BY SUM(rating) DESC LIMIT 1);`. The salesperson with the highest customer ratings in the dataset is 'Giovanni' who is served by salesperson with snum 1003.
To determine the number of unique customers per salesperson, use the SQL query: `SELECT snum, COUNT(DISTINCT cnum) FROM customer GROUP BY snum;`. For the dataset, the results show: snum 1001 has 2 customers, snum 1002 has 3 customers, and snum 1003 has 1 customer.
To find salespeople who have customers from their own city, the query would be: `SELECT sname FROM salespeople WHERE city IN (SELECT city FROM customer WHERE salespeople.snum = customer.snum);`. For the given dataset, the salesperson 'Rifkin' from Barcelona matches this condition because they have customers from the same city.
The SQL query to list students from Pune is: `SELECT * FROM student WHERE city='Pune';`. The results from the dataset would be: VARKALA TEJASRI, EDUNURI BHAVIKA, BEJAGAM CHETHAN TEJA, BHUKYA SRIDHAR, SHIVA KUMAR, and MOUNIKA.
To determine which salesperson should be fired, we could look at metrics such as the number of customers managed by each salesperson or their effectiveness based on customer ratings. However, the data provides a suggestion to fire based on whether a salesperson is linked to any orders or customer ratings. Therefore, you could query for salespeople with the lowest customer ratings or the fewest orders. For instance, `SELECT sname FROM salespeople WHERE snum NOT IN (SELECT DISTINCT snum FROM customer);` If all salespeople have at least one customer, further analysis is needed on the orders they are associated with for any inference on who should be fired.
The SQL query to retrieve the top-performing student in Hyderabad would be: `SELECT * FROM student WHERE city='Hyderabad' ORDER BY marks DESC LIMIT 1;`. According to the data, the top-performing student in Hyderabad is C PRADEEP, with a score of 95.