2024.10.15 sql

 刷题网站:

牛客网


select device_id as user_infos_example
from user_profile where id <= 2
select device_id, university from user_profile
where university="北京大学"
select device_id, gender, age, university
from user_profile
where age > 24

between and 是左右闭区间[] 

select device_id, gender, age
from user_profile
where age between 20 and 23

单引号! 

select device_id, gender, age, university 
from user_profile
where university!='复旦大学'

格式化sql语句

selectdevice_id,gender,age,university,gpa
fromuser_profile
wheregpa > 3.5 and university = '山东大学'orgpa > 3.8 and university = '复旦大学'

%表示0个或多个字符 

selectdevice_id,age,university
fromuser_profile
whereuniversity like '%北京%'
selectmax(gpa)
fromuser_profile
whereuniversity = '复旦大学'
selectcount(gender) as male_num,avg(gpa) as avg_gpa
fromuser_profile
wheregender = 'male'

有没有人管管牛客网,怎么代码一模一样的,第一次对,第二次不多ToT!

selectgender,university,count(*) as user_num,avg(active_days_within_30) as avg_active_day,avg(question_cnt) as avg_question_cnt
fromuser_profile
group bygender, university

加round()默认四舍五入到小数点后一位

selectdevice_id,age
fromuser_profile
order byage asc
selectdevice_id,gpa,age
fromuser_profile
order bygpa asc,age asc
selectdevice_id,gpa,age
fromuser_profile
order bygpa desc,age desc
selectcount(distinct device_id) as did_cnt,count(*) as question_cnt
fromquestion_practice_detail
wheredate like "2021-08%"
selectuniversity,round(avg(question_cnt),3) as avg_question_cnt,round(avg(answer_cnt),3) as avg_answer_cnt
fromuser_profile
group byuniversity
havingavg_question_cnt < 5oravg_answer_cnt < 20
selectuniversity,round(avg(question_cnt), 4) as avg_question_cnt
fromuser_profile
group byuniversity
order byavg_question_cnt asc
selectqd.device_id,qd.question_id,qd.result
fromquestion_practice_detail as qdinner joinuser_profile as upon qd.device_id = up.device_idandup.university = '浙江大学'
order bydevice_id

selectup.university,round(count(question_id)/count(distinct qpd.device_id),4) as avg_answer_cnt
fromquestion_practice_detail as qpdinner joinuser_profile as uponqpd.device_id = up.device_id
group byup.university
  • INNER JOIN:

    • 只返回两个表中匹配的记录。当连接的表中没有匹配的行时,这些行将不会出现在结果集中。
  • LEFT JOIN (或 LEFT OUTER JOIN):

    • 返回左表(第一个表)中的所有记录,即使在右表(第二个表)中没有匹配的记录。如果右表中没有匹配的行,结果集中对应的右表字段将显示为 NULL
selectue.university as university,ql.difficult_level as difficult_level,round(count(qpl.question_id)/count(distinct(qpl.device_id)),4) as avg_answer_cnt
fromquestion_practice_detail as qplleft joinuser_profile as ueon qpl.device_id = ue.device_idleft joinquestion_detail as qlon qpl.question_id = ql.question_id
group byue.university,ql.difficult_level
selectt1.university as university,t3.difficult_level as difficult_level,round(count(t2.question_id) / count(distinct (t2.device_id)),4) as avg_answer_cnt
fromuser_profile as t1,question_practice_detail as t2,question_detail as t3
wheret1.university = '山东大学'and t1.device_id = t2.device_idand t2.question_id = t3.question_id
group byt3.difficult_level

UNION vs UNION ALL

  • UNION:合并多个查询的结果集,自动去重,即如果两个查询的结果中有相同的行,最终结果集中只保留一行。
  • UNION ALL:合并多个查询的结果集,包括所有的行,不去重,即使有重复的行,也会全部显示。
selectcasewhen age<25 or age is null then "25岁以下"else "25岁及以上"end as age_cut,count(device_id) as number
fromuser_profile
group byage_cut
selectdevice_id,gender,casewhen age < 20 then '20岁以下'when age between 20 and 24  then '20-24岁'when age >= 25 then '25岁及以上'else '其他'end as age_cut
fromuser_profile;
selectDAY(date) as day,count(*) as question_cnt
fromquestion_practice_detail as ql
whereql.date like '2021-08-%'
group byql.date

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/881862.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt_打开其他软件(带参数)

文章内容: 当打开器他软件并要求其他软件做出响应动作时,我们可以通过传入参数来控制软件打开的方式。 打开软件: if(QString::compare(ui->btn_connect->text(), "断开连接") ==

MySQL学习(六):视图和存储过程以及函数

MySQL学习&#xff08;六&#xff09;&#xff1a;视图和存储过程以及函数 文章目录 MySQL学习&#xff08;六&#xff09;&#xff1a;视图和存储过程以及函数1. 视图1.1 视图的作用与特性1.2 视图的创建1.3 视图的查看与维护1.4 视图的修改与删除 2. 存储过程与函数2.1 存储过…

Windows 添加右键以管理员身份运行 PowerShell

在 Windows 系统中添加一个右键菜单选项&#xff0c;以便可以使用管理员权限打开 PowerShell&#xff0c;可以通过编辑注册表来实现。 打开注册表编辑器&#xff1a; 按 Win R 打开运行对话框。输入 regedit 并按回车&#xff0c;这将打开注册表编辑器。 导航到文件夹背景键&…

计算机毕业设计Django+Vue.js豆瓣图书推荐系统 图书评论情感分析 豆瓣图书可视化大屏 豆瓣图书爬虫 数据分析 图书大数据 大数据毕业设计 机器学习

《DjangoVue.js豆瓣图书推荐系统》开题报告 一、研究背景与意义 1. 研究背景 随着数字化时代的来临&#xff0c;图书资源日益丰富&#xff0c;用户面临着信息过载的问题。如何在海量图书中快速找到符合个人兴趣和需求的书籍成为了亟待解决的问题。传统的图书检索方式往往基于…

javaweb以html方式集成富文本编辑器TinyMce

前言&#xff1a; 单一的批量图片上传按钮&#xff0c;禁用tinymce编辑器&#xff0c;但是还可以操作图片编辑&#xff1b; 多元化格式的富文本编辑要求&#xff1b; 采用tinymce实现。 附&#xff1a; tinymce中文手册网站&#xff1a; http://tinymce.ax-z.cn/download-all.…

空间解析几何 3:空间点到线段和平面的距离【附MATLAB代码】

目录 空间中点到线段的距离 空间中点到平面的投影和距离 matlab代码 空间中点到线段的距离 空间中点到平面的投影和距离 matlab代码 function [dis,P2,t] point2Line (A1,B1,C1) %求空间一点到一线段的最短距离 %[dis,P2,Q2]pointSegmentDistance(A,B,C) %A B为线段首末端…

使用LlamaFactory进行模型微调

使用LlamaFactory进行模型微调 简介 论文地址&#xff1a;https://arxiv.org/pdf/2403.13372 仓库地址&#xff1a;https://github.com/hiyouga/LLaMA-Factory/tree/main 名词解释 1. 预训练 (Pre-training, PT) 预训练是指模型在大规模无监督数据集上进行初步训练的过程…

最强 OpenAI o1 逻辑推理正确率仅 50%!清华、智谱推出「大模型逻辑推理新基准」

9.11 和 9.9 哪个大&#xff1f; 这一连人类幼儿园儿童都能回答的问题&#xff0c;曾经&#xff08;至今&#xff09;难倒了众多大语言模型&#xff08;LLM&#xff09;。 然而&#xff0c;要想达到通用人工智能&#xff08;AGI&#xff09;的水平&#xff0c;LLM 不仅要完成“…

居民小区的有序充电策略及解决方案

0引言 全球经济增长导致化石能源过度消耗&#xff0c;加剧环境污染。电动汽车因其环保优势迅速崛起&#xff0c;预计到2030年中国电动汽车保有量将达到6000万辆。这有助于减少化石能源依赖&#xff0c;推广绿色出行&#xff0c;但也对电网稳定性构成挑战。因此&#xff0c;研究…

2.1 HTML5 - Canvas标签

文章目录 引言Canvas标签概述定义实例&#xff1a;创建画布 理解Canvas坐标系概述实例&#xff1a;获取Canvas坐标 获取Canvas环境上下文概述实例&#xff1a;获取Canvas上下文设置渐变色效果 结语 引言 大家好&#xff0c;今天我们要一起探索HTML5中一个非常有趣且强大的特性…

001 Hadoop安装、Spring整合测试

Hadoop安装、整合测试 文章目录 Hadoop安装、整合测试1.简介1.优点2.组成 2.安装1.安装jdk&#xff08;如已安装可跳过&#xff09;2.安装hadoop1.安装2. 修改配置文件core-site.xml3. 修改配置文件hdfs-site.xml4.启动hadoop5.启动yarn6.执行jps查看7.相关端口及配置位置8.访问…

Python数学难题:科拉兹猜想(又称为 3x+1 猜想、角谷猜想、哈塞猜想、冰雹猜想、乌拉姆猜想或叙拉古猜想)

Python数学难题&#xff1a;科拉兹猜想&#xff08;又称为 3x1 猜想、角谷猜想、哈塞猜想、冰雹猜想、乌拉姆猜想或叙拉古猜想&#xff09; 科拉兹猜想&#xff0c;又称为 3x1 猜想、角谷猜想、哈塞猜想、冰雹猜想、乌拉姆猜想或叙拉古猜想&#xff0c;是一个与自然数相关的猜…

查找占用特定端口程序,并杀死

windows 在 Windows 上查找和结束占用特定端口&#xff08;如 9003&#xff09;的程序&#xff0c;你可以使用以下步骤&#xff1a; 步骤 1&#xff1a;找到占用端口的进程 ID (PID) 打开命令提示符&#xff08;按 Win R&#xff0c;输入 cmd&#xff0c;然后按回车&#x…

技术框架官方写法

知识背景&#xff1a; 在做汇报工作或者撰写简历的时候需要用到&#xff0c;希望对大家有帮助 总体介绍&#xff1a; Java: 始终保持 "Java" 的"J"大写&#xff0c;因为这是Oracle Corporation注册的商标。Spring Framework: 通常称其为 "Spring&q…

【React】事件绑定的方式

1. 内联函数绑定 这是最简单直接的方式&#xff0c;即在 JSX 语法中直接传递一个内联函数。这种方式每次渲染时都会创建新的函数实例&#xff0c;可能会导致不必要的性能开销。 class MyComponent extends React.Component {render() {return (<button onClick{() > th…

python中不变的数据类型有哪些

在Python中&#xff0c;不可变&#xff08;immutable&#xff09;数据类型是指一旦创建了这些类型的对象后&#xff0c;就不能改变其值。Python中的不可变数据类型包括以下几种&#xff1a; 数字 (int, float, complex): 这些类型的数值一旦创建就不能更改。例如&#xff0c;如…

速盾:高防服务器防火墙的特性是什么?

高防服务器防火墙是一种专业的网络安全设备&#xff0c;用于保护服务器免受各种网络攻击的侵害。它具有许多特性&#xff0c;以确保服务器的安全性和可靠性。 第一个特性是入侵检测系统&#xff08;IDS&#xff09;。高防服务器防火墙可以监视服务器上的网络流量&#xff0c;并…

使用Python实现深度学习模型:智能产品设计与开发

在智能产品设计与开发领域,深度学习模型的应用越来越广泛。本文将介绍如何使用Python构建一个简单的深度学习模型,并将其应用于智能产品的设计与开发。为了使内容尽可能通俗易懂,我们将以图像分类为例,详细讲解每一步骤。 1. 深度学习基础 深度学习是一种基于人工神经网络…

Spring Boot中使用MyBatis-Plus和MyBatis拦截器来实现对带有特定注解的字段进行AES加密。

1. 添加依赖 首先&#xff0c;在pom.xml文件中添加必要的依赖项&#xff1a; xml 深色版本 <dependencies> <!-- Spring Boot Starter Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifac…

三级等保对postgresql的安全要求配置

密码策略 select * from pg_user select * from pg_settings; show password_encryption; show shared_preload_libraries; alter username postgres valid until 2024-05-11;日志审计 select name,setting from pg_settings where namelogging_collector or namelog_line_pr…