1.查询每个班级的前三名

DROP TABLE IF EXISTS `sc`;
CREATE TABLE `sc` (
`id` int() NOT NULL AUTO_INCREMENT,
`name` varchar() CHARACTER SET utf8 DEFAULT NULL,
`class` varchar() CHARACTER SET utf8 DEFAULT NULL,
`score` int() DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=latin1; insert into sc values (,'badkano','一年一班',);
insert into sc values (,'百度知道团长','一年一班',);
insert into sc values (,'du小短','一年一班',);
insert into sc values (,'du小小动','一年一班',);
insert into sc values (,'du小智','一年一班',);
insert into sc values (,'吕布','一年二班',);
insert into sc values (,'赵云','一年二班',);
insert into sc values (,'典韦','一年二班',);
insert into sc values (,'关羽','一年二班',);
insert into sc values (,'马超','一年二班',);

result:

select
*
from sc t
where
(select count()+ from sc where class=t.class and score>t.score)
<= 3

SELECT *
FROM sc a
WHERE 3 > (
SELECT COUNT( * )
FROM sc
WHERE class = a.class
AND score > a.score )
ORDER BY a.class , a.score DESC

2.关于null的查询

查询:

select * from t_category where description<>''
select * from t_category where description=''

这两条查询都只有一条记录,并没有查询出为null的记录

select sum(user_id) as ids from t_category where description='aaaaa'

结果不是为0,是null

3.mysql中逗号字符串与数字比较

       select =;  -- true

        select cast( as char())=;  -- true

        select cast( as char())=;  -- false

        select cast('5,2' as char())=;  -- true

        select '5,2,4'=; -- true

        select ='5,4';   -- true

        select ='5^4';  -- true

        select ='5|4';  -- true

        select ='5.4';  -- false

结果莫名其妙,除了点号以外,其他符号间隔的第一个符号与数字匹配就为true,看不懂,以后遇到要注意。

4.mysql中find_in_set使用

        select find_in_set('b','a,b,c,d,e,f');   -- 

        select find_in_set('d','a,b,c,d,e,f');   --   

mysql字符串函数 find_in_set(str1,str2)函数是返回str2中str1所在的位置索引,str2必须以","分割开。

like是广泛的模糊匹配,字符串中没有分隔符,Find_IN_SET 是精确匹配,字段值以英文”,”分隔,Find_IN_SET查询的结果要小于like查询的结果。

https://zhidao.baidu.com/question/117048828.html

https://blog.csdn.net/zoujian1993/article/details/48243139

http://www.manongjc.com/article/1081.html

https://my.oschina.net/u/1032146/blog/149300

Mysql相关问题收集的更多相关文章

  1. MySQL相关参数总结

    保留个原文链接,避免被爬虫爬了过去,以便后续更正补充:https://www.cnblogs.com/wy123/p/11273023.html MySQL参数繁多,是一个需要根据具体业务.软硬件环境 ...

  2. 关于MySQL相关的查看显示信息:

    关于MySQL相关的查看显示信息: 数据库范围: 一.查看所有的数据库:(仅仅是看数据库数量与名字) mysql> show databases; 二.查看某个数据库的创建信息:(主要看数据库的 ...

  3. AssetBundle机制相关资料收集

    原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...

  4. Linux 之 rsyslog+mysql+LogAnalyzer 日志收集系统

     作者:邓聪聪 LogAnalyzer 是一个 syslog 和其他网络事件数据的 Web 前端工具,提供简单易用的日志浏览.搜索和基本分析以及图表显示 由于公司部分项目需求使用日志记录系统,随笔记录 ...

  5. .NetCore关于Cap(RabbitMQ)结合MySql使用出现MySql相关类冲突问题解决办法

    问题还原 引用了 DotNetCore.CAP.MySql MySql.Data.EntityFrameworkCore 在使用MySql相关对象的时候会出现如下冲突,在命名空间加入伪空间名称是不能解 ...

  6. oracle相关命令收集-张

    orcle相关命令收集 1,用管理员登陆 /as sysdba:2, 更改用户密码 alter user name identified by password: alter user exptest ...

  7. MySQL相关问题总结

    希望此贴能够将MySQL安装周围的问题总结清楚,也免得自己再遇到问题时而不知所措.本帖中所有关于MySQL的问题均涉及到两个平台:Ubuntu 和 Windows(本人没有Mac) 问题1:MySQL ...

  8. FastAdmin CMS 插件相关文章收集(2018-08-16)

    FastAdmin CMS 插件相关文章收集(2018-08-16) CMS内容管理系统(含小程序) 介绍 https://www.fastadmin.net/store/cms.html CMS内容 ...

  9. FastAdmin 导出 Excel 相关资料收集 (2018-08-14)

    FastAdmin 导出 Excel 相关资料收集 导出 Excel 文件时身份证号变成科学计数法怎么办? https://forum.fastadmin.net/thread/1346 姊妹篇 Fa ...

随机推荐

  1. ls 列出文件目录(可以含子目录)及文件的完整路径

    1.列出当前目录的文件.文件夹完整路径    ls -1 |awk '{print i$0}' i=`pwd`'/' 2.列出当前目录及子目录的文件.文件夹完整路径    ls -R |awk '{p ...

  2. js判断字符串长度

    方法1: String.prototype.gblen = function() { var len = 0; for (var i=0; i<this.length; i++) { if (t ...

  3. 【剑指offer】 二叉树中和为某一值的路径

    一.题目: 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度 ...

  4. [py]python的私有变量

    参考 python中并没有真正意义上的私有成员,它提供了在成员前面添加双下划线的方法来模拟类似功能.具体来说: _xxx 表示模块级别的私有变量或函数 __xxx 表示类的私有变量或函数 这被称为na ...

  5. PAT 1016 Phone Bills[转载]

    1016 Phone Bills (25)(25 分)提问 A long-distance telephone company charges its customers by the followi ...

  6. GCC编译器ABI

    ABI与EABI 1)ABI(Application Binary Interface for the ARM Architecture),描述了应用程序与cpu内核的低级接口. ABI允许编译好的目 ...

  7. 187. Repeated DNA Sequences(建立词典,遍历一遍 o(n))

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  8. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  9. FastReport问题整理(转)

    FastReport问题整理 博客分类: 软件开发   部分来自网上,部分来自网友,部分来自Demo如果有新的内容,会不断更新.. 更新历史: 2009-02-27 加入套打方案全攻略(原:jinzh ...

  10. EF Code First学习笔记 初识Code First(转)

    Code First是Entity Framework提供的一种新的编程模型.通过Code First我们可以在还没有建立数据库的情况下就开始编码,然后通过代码来生成数据库. 下面通过一个简单的示例来 ...