查询结果限制返回行数_牛客题霸_牛客网
例如返回前两行
检索记录行 6-10
SELECT
*
FROM
table
LIMIT 5,5
检索记录行 11-last
SELECT
*
FROM
table
LIMIT 10,-1
计算25岁以上和以下的用户数量_牛客题霸_牛客网
查询结果:
SELECT IF(age>=25,"25岁及以上","25岁以下") AS age_cut,count(device_id) AS number
FROM user_profile
GROUP BY age_cut;
select
CASE
when age < 25 or age is null then '25岁以下'
when age >= 25 then '25岁以上'
end as age_cut, count(device_id) number
from user_profile
group by age_cut
如果年龄为空,年龄一行设置为其他
select device_id,gender,
case
when age < 20 then '20岁以下'
when age >= 20 and age < 24 then '20-24岁'
when age >= 25 then '25岁及以上'
else '其他'
end as age_cut
from user_profile
计算用户8月每天的练题数量_牛客题霸_牛客网
年:year(date) = '2021' 或者 date like ('2021%')
月:month(date)
日:day(date)
统计每种性别的人数_牛客题霸_牛客网
统计每个性别的用户分别有多少参赛者,并且按照人数从小到大排列:
提示:从小到大---asc ,从大到小---desc
select
case
when profile like '%,male' then 'male'
when profile like '%,female' then 'female'
end as gender,
count(device_id) as number
from user_submit
group by gender
order by number asc
例如:http:/ur/bisdgboy777 改为 ur/bisdgboy777
对应题目:提取博客URL中的用户名_牛客题霸_牛客网
device_id, replace(blog_url,'http:/url/','') as user_name
device_id, substr(blog_url,11,length(blog_url)-10) as user_nam
device_id, trim('http:/url/' from blog_url) as user_name
device_id, substring_index(blog_url,'/',-1) as user_name
结果
select device_id, university,gpa
from user_profile u1
where gpa <= (
select min(gpa)
from user_profile u2
where u1.university = u2.university
group by university
)
order by university asc
查询结果去重_牛客题霸_牛客网
select university from user_profile group by university
或者
SELECT DISTINCT university from user_profile