查询以选择具有条件的最小值 [英] query to select the minimum value with a condition
问题描述
看我的桌子
桌面名称:special_ad
id video_id play_mode play_count
1 15 both 2
2 16 after 2
3 17 before 1
4 18 both 2
5 19之后2
现在我想选择一个等于'之前'的play_mode音符,playcount是最小的。
我正在使用以下查询,但它返回一个空值
从special_ad中选择video_id,playmode,play_count,其中play_count =(从special_ad中选择min(play_count),其中playmode<> ;'之前')
如果'之前'的play_count应该高于其他人,它将检索
请提示更好的方法
你的查询运行良好
S.选择 video_id,play_mode,play_count 来自 video_tbl
其中 play_count =(选择 min(play_count)来自 video_tbl 其中 play_mode! = ' 在' group by play_count)
此查询的输出是
video_id play_mode play_count
15 2
16 2
18 在 2之后 2
19 跨度>
look my table
table name: special_ad
id video_id play_mode play_count
1 15 both 2
2 16 after 2
3 17 before 1
4 18 both 2
5 19 after 2
now i want to select a play_mode note equal to 'before' and playcount is minimum.
i'm using the following query but it returns a null value
Select video_id,playmode,play_count from special_ad where play_count=(select min(play_count) from special_ad where playmode<>'before')
it will retrieve if the play_count of 'before' should be higher than others
pls suggest a better way
your Query running well
Select video_id,play_mode,play_count from video_tbl where play_count=(select min(play_count)from video_tbl where play_mode !='before' group by play_count )
the output of this query is
video_id play_mode play_count 15 both 2 16 after 2 18 both 2 19 after 2
这篇关于查询以选择具有条件的最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!