Double query statement

Asked 2 years ago, Updated 2 years ago, 95 views

ex) select distinct(user_level) from UserInfo;

ex) select min(play_time) from UserInfo where user_lever in(select distinct(user_level) from UserInfo)

I thought this would list the minimum play time for each level The result shows the minimum play time for the entire table.

In conclusion, what I want to do is to get a table from Result_1

user_level

1

3

4

10

Select min(play_time) from UserInfowhere sequentially in the where clause of the query statement I want to apply it.

select min(play_time) from UserInfo where =1

select min(play_time) from UserInfo where =3

select min(play_time) from UserInfo where =4

select min(play_time) from UserInfo where =10

I want to apply it as above, what should I do?(Is there too many levels to work?) ㅜ))

mysql querying

2022-09-21 20:12

1 Answers

I think you want to classify users by level and find how quickly each level was resolved (?) = min(play_time).

In this case, you can use the group_by statement instead of using join. The group_by statement groups the table by a specific criterion. The aggregation of queries using the group_by statement is applied per group.

Please refer to the following code.

select user_level, min(play_time) from UserInfo group by user_level;


2022-09-21 20:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.