At Perfect World Entertainment, SQL is typically used for analyzing player behavior patterns and optimizing the performance of online gaming servers. Because of this, Perfect World Entertainment almost always asks SQL query questions in interviews for Data Science, Data Engineering and Data Analytics jobs.
To help you ace the Perfect World Entertainment SQL interview, we've curated 8 Perfect World Entertainment SQL interview questions – can you answer each one?
Perfect World Entertainment is primarily recognized for its strong portfolio of online games. To keep a track of user activity and identify VIP users, we want to analyze the user_gameplay table. A VIP user is defined as a user who played any of their games for more than 1000 hours in the past month. Write a SQL query to find out the user_id and the total gameplay hours of these power users.
user_id | game_id | play_time_hours | play_date |
---|---|---|---|
1001 | 1003 | 300 | 07/05/2022 |
1002 | 1005 | 1300 | 07/05/2022 |
1003 | 1004 | 50 | 07/05/2022 |
1004 | 1006 | 1010 | 07/05/2022 |
1005 | 1007 | 890 | 07/05/2022 |
Here's a SQL block that could answer the problem:
This SQL query first filters out all the play records in the current month using the WHERE clause. After that, it groups the records by user_id and calculates the total play time for each user in the past month by the sum function in the SELECT statement. Finally, it filters out users with total play times more than 1000 hours by the HAVING clause. So the result of this SQL query is the user_id and total play time of VIP users.
To solve a similar VIP customer analysis question on DataLemur's free interactive SQL code editor, try this Microsoft Azure Cloud SQL Interview Question:
As a data analyst for Perfect World Entertainment, a popular gaming company, you are asked to analyze and provide insights about in-game purchases for their popular game "Heaven of Swords". The company wants to understand about monthly trends in in-game purchases, for that you need to write a SQL query to calculate the sum of in-game purchase for each month, for each user.
purchase_id | user_id | purchase_date | game_id | amount |
---|---|---|---|---|
8731 | 123 | 06/05/2022 00:00:00 | 742003 | 30 |
8952 | 265 | 06/12/2022 00:00:00 | 742003 | 70 |
9529 | 362 | 06/15/2022 00:00:00 | 742003 | 50 |
10835 | 192 | 07/20/2022 00:00:00 | 742003 | 90 |
10130 | 981 | 07/13/2022 00:00:00 | 742003 | 60 |
mth | user_id | total_amount |
---|---|---|
6 | 123 | 30 |
6 | 265 | 70 |
6 | 362 | 50 |
7 | 192 | 90 |
7 | 981 | 60 |
The query above employs the PostgreSQL window function . What it does is it groups the data by user_id and orders by year and month of purchase_date, then calculates the sum for each group. The statement is used to filter the data specifically for game "Heaven of Swords". The function is used to pull out only the month from the purchase_date and year respectively.
For more window function practice, solve this Uber SQL problem within DataLemur's interactive coding environment:
A primary key is a column or set of columns in a table that uniquely identifies each row in the table. The primary key is used to enforce the uniqueness and non-nullability of the rows in the table.
In a SQL database, a primary key is defined using the constraint. For example, say you had a table of :
In this example, the column is the primary key of the Perfect World Entertainment employees table. It is defined as an integer and is marked as the primary key using the constraint.
A table can have only one primary key, but the primary key can consist of multiple columns. For example, say you had a table of Perfect World Entertainment customer transactions:
In the above example, the primary key of the Orders table consists of two columns: TransactionID and ProductID. This means that the combination of OrderID and ProductID must be unique for every row in the table.
Perfect World Entertainment is a leading online publisher of live service games in North America and Europe. They are known for creating games that foster powerful communities. They are interested in understanding the click-through rates of their demos to actual purchases for their games.
They track two main events:
The data is logged in two separate tables, and .
click_id | user_id | click_date | game_id |
---|---|---|---|
1111 | 101 | 2022-08-30 | 1 |
1112 | 102 | 2022-08-31 | 2 |
1113 | 103 | 2022-09-01 | 3 |
1114 | 104 | 2022-09-02 | 1 |
1115 | 105 | 2022-09-03 | 2 |
purchase_id | user_id | purchase_date | game_id |
---|---|---|---|
2101 | 101 | 2022-09-01 | 1 |
2102 | 103 | 2022-09-02 | 3 |
2103 | 104 | 2022-09-03 | 1 |
Write a SQL query to calculate the percentage of demo clicks that result in a purchase for each game. This will help Perfect World Entertainment understand which games have the highest conversion rate from demo to purchase.
This query works by joining the and tables on and . It counts the distinct number of users who made a purchase (represented by ) and divides it by the total number of users who clicked the demo (represented by ). We use to ensure that the result is a decimal number. The result is grouped by to get the click-through-to-purchase ratio for each game.
To solve a similar problem about calculating rates, try this TikTok SQL question within DataLemur's online SQL code editor:
In a database, constraints are rules that the DBMS (database management system) follows when performing operations such as inserting, updating, or deleting data.
For example, consider a table of employee records at Perfect World Entertainment. Some constraints that you might want to implement include:
Given the following two tables, and , write a SQL query to list out the average spending of customers on different games.
table contains customer information including customer id, name, and registration date. table contains transactional data such as game id, customer id, transaction date, and amount spent on the games.
For the output, provide a table listing out the customer names along with the average spending on each unique game.
customer_id | customer_name | registration_date |
---|---|---|
101 | John Doe | 2020-01-10 |
102 | Jane Smith | 2020-02-15 |
103 | Jim Brown | 2020-03-20 |
104 | Janet Wilson | 2020-04-25 |
105 | Jennifer Lewis | 2020-05-30 |
game_id | customer_id | transaction_date | amount_spent |
---|---|---|---|
201 | 101 | 2020-01-20 | 50 |
202 | 101 | 2020-02-20 | 60 |
203 | 102 | 2020-02-25 | 70 |
204 | 103 | 2020-03-21 | 85 |
205 | 104 | 2020-04-28 | 90 |
This query first joins the and tables on the field. The clause is then used to group records by unique customer and game pairs (i.e. it considers each customer's spending on separate game as a unique condition). function is then used to calculate average spending of each customer on each individual game. Finally, the results are ordered by customer names.
Since joins come up so often during SQL interviews, practice an interactive Spotify JOIN SQL question:
The / operator is used to remove to return all rows from the first SELECT statement that are not returned by the second SELECT statement.
Note that is available in PostgreSQL and SQL Server, while MINUS is available in MySQL and Oracle (but don't worry about knowing which DBMS supports which exact commands since Perfect World Entertainment interviewers aren't trying to trip you up on memorizing SQL syntax).
For a tangible example of in PostgreSQL, suppose you were doing an HR Analytics project for Perfect World Entertainment, and had access to Perfect World Entertainment's contractors and employees data. Assume that some employees were previously contractors, and vice versa, and thus would show up in both tables.
You could use operator to find all contractors who never were a employee using this query:
Perfect World Entertainment wants to analyze the login habits of their players. Given the table of login timestamps, can you write a query to find out the players who have logged in daily for more than seven consecutive days? The start and end date of each players consecutive login span should also be included in your output.
player_id | login_date |
---|---|
1089 | 2022-07-08 15:09:55 |
1089 | 2022-07-09 17:43:25 |
1089 | 2022-07-10 11:34:02 |
1089 | 2022-07-11 07:08:14 |
1089 | 2022-07-12 21:15:06 |
1089 | 2022-07-13 19:34:11 |
1089 | 2022-07-14 23:23:45 |
1089 | 2022-07-15 08:00:55 |
3021 | 2022-07-12 10:08:01 |
3021 | 2022-07-13 12:46:25 |
player_id | start_date | end_date |
---|---|---|
1089 | 2022-07-08 | 2022-07-15 |
In this solution, we first partition the table by and order by , and subtract a row number from the date. If the players logged in on consecutive days, then this would result in a constant value which helps to group the consecutive dates (grp). Then, in the outer query, we compute the minimum and maximum date for each group and the player_id, and only keep those groups that have more than 7 dates.
The best way to prepare for a SQL interview, besides making sure you have strong SQL fundamentals, is to practice a ton of real SQL questions that were asked in recent job interviews. In addition to solving the earlier Perfect World Entertainment SQL interview questions, you should also solve the 200+ FAANG SQL Questions on DataLemur which come from companies like Google, Uber, and Microsoft.
Each interview question has hints to guide you, fully explained answers along with a discussion board to see how others solved it and crucially, there is an online SQL code editor so you can instantly run your SQL query and have it graded.
To prep for the Perfect World Entertainment SQL interview it is also helpful to practice interview questions from other tech companies like:
But if your SQL foundations are weak, forget about going right into solving questions – improve your SQL foundations with this DataLemur SQL Tutorial.
This tutorial covers things like filtering data with boolean operators and transforming strings with CONCAT()/LOWER()/TRIM() – both of which pop up often during SQL job interviews at Perfect World Entertainment.
Beyond writing SQL queries, the other question categories to practice for the Perfect World Entertainment Data Science Interview are:
To prepare for Perfect World Entertainment Data Science interviews read the book Ace the Data Science Interview because it's got: