-- 对所有用户的年龄进行累加求和 selectSUM(u.AGE) from t_user u ;
2. CASE WHEN <条件> THEN <满足条件的结果> ELSE <不满足条件的结果> END
CASE <条件字段> WHEN <值1> THEN <满足条件=值1的结果> WHEN <值2> THEN <满足条件=值2的结果> ... ELSE <不满足所有条件的结果> END
1 2 3 4 5 6 7 8 9 10 11 12
--eg:查询年龄大于18的flag输出成年人,否则未成年人 selectCASEWHEN u.age>18THEN'成年人'ELSE'未成年人'ENDas flag from t_user u; --eg:多条件组合查询年龄大于18且是男的的flag输出男成年人,否则未成年人 selectCASEWHEN u.age>18and u.sex='男'THEN'男成年人'ELSE'未成年人'ENDas flag from t_user u; --按条件统计总数,sum是求和,输出只能是1 ELSE 0,因为要进行累加 --统计大于18的总人数 selectsum(CASEWHEN u.age>18THEN1ELSE0END) as total from t_user u; --多条件switch实现,将boy替换成男,girl替换成女,其他输出人妖 selectCASE u.sex WHEN'boy'THEN'男' WHEN'girl'THEN'女' ELSE'人妖'ENDfrom t_user u;
--将boy替换成男,girl替换成女,其他输出人妖,等效于case when select DECODE(u.SEX,'boy','男','girl','女','人妖') from t_user u;
4. NVL(<需要判断的字段>,<如果判断的字段为null输出的结果>)
1 2 3 4
--数据为null的会替换成人妖 select nvl(u.SEX,'人妖') from t_user u; --没有年龄的设置为0,方便统计空数据 selectsum(nvl(u.age,0)) from t_user u;
5. group by <分组的字段1,字段2...>分组统计
select后面的字段=分组的字段+统计求和等字段,原理分组过后,查询不能查一个组有多个不同结果的字段,如果是相同的结果加入group by 字段1,字段2
1 2 3 4
--按年龄分组统计各个年龄的总数 select u.AGE,count(u.SEX) from T_USER u groupby u.AGE; --按年龄性别进行分组统计,统计年龄相同且性别相同的个数 select u.AGE,u.SEX,count(*) from T_USER u groupby u.AGE,u.SEX
--sysdate获取当前日期,to_char格式化为天 select to_char(sysdate, 'yyyy-MM-dd') from DUAL; --按天分组统计 selectsum(1),to_char(u."creat_time",'YYYY-MM-DD') asdayfrom t_user u groupby to_char(u."creat_time",'YYYY-MM-DD'); --按月分组统计,按年等其他日期类似 selectsum(1),to_char(u."creat_time",'YYYY-MM') asdayfrom t_user u groupby to_char(u."creat_time",'YYYY-MM'); --查询7天前的数据,其他天类似 select*from T_USER u where to_char(u."creat_time",'yyyy-MM-dd')>to_char(sysdate-7, 'yyyy-MM-dd') --统计查询前7天的数据,当天没有统计为0,按时间降序 select t_date.day, NVl(t_data.total, 0) from (select TO_CHAR(trunc(sysdate +1- ROWNUM), 'yyyy-MM-dd') dayfrom DUAL connectby ROWNUM <=7) t_date leftjoin (select to_char(u."creat_time", 'yyyy-MM-dd') asday, count(1) as total from T_USER u groupby to_char(u."creat_time", 'yyyy-MM-dd')) t_data on t_data.day = t_date.day orderby t_date.day asc;
7. round(<小数>,<保留小数点后位数>)
1 2
--保留小数点后2位,输出33.33 select round( 1/3*100 ,2) from dual;
8. left join 左连接
以左边为主,右边有就连接,没有就null
1
select*from T_USER l leftjoin T_USER r on l.AGE=r.FLAG;
9. substr(<需要裁剪的字符串>,<开始位置>, <结束位置>)
1 2
-- 输出2019 select substr('2019-01-02',1, 4) from DUAL;
10. connect by
其他用法,获取树形数据(也就是父子关系)见google
rownum数据库关键字,行数
1 2 3 4
--生成1-10的序列 select rownum from dual connectby rownum<=10; --生成7天的日期 select TO_CHAR(trunc(sysdate+1-ROWNUM),'yyyy-MM-dd') dd from DUAL connectby ROWNUM <=7
11. union <all> 两个结果集合并
有all 全连接,不去重,没有all 去重
1 2 3 4 5 6 7 8
-- 输出1-4-1-4 select rownum from dual connectby rownum<=4 unionall select rownum from dual connectby rownum<=4; -- 输出1-4 select rownum from dual connectby rownum<=4 union select rownum from dual connectby rownum<=4;
12. ROLLUP 分组汇总
ROLLUP汇总分组排列在最后一条数据,但是数据头为null,可以通过null判断取别名为总数
1 2 3 4 5 6 7 8 9 10 11 12 13 14
SELECT nvl(CASE WHEN sex ='boy'THEN'男' WHEN sex ='girl'THEN'女' ELSE'人妖' END, '总数') AS type, count(1) as num from t_user GROUPBY ROLLUP ( CASE WHEN sex ='boy'THEN'男' WHEN sex ='girl'THEN'女' ELSE'人妖' END);
13. ||字符连接符
用于单位,用于多条数据拼接
1 2 3 4
select'sex是'||u.SEX||',年龄是'||u.AGE as detail from T_USER u; --------输出结果------ --sex是boy,年龄是1 --sex是girl,年龄是2
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'NVSSDK': libNVSSDK.so: 无法打开共享对象文件: 没有那个文件或目录 libossdk.so: 无法打开共享对象文件: 没有那个文件或目录 Native library (linux-x86-64/libNVSSDK.so) not found in resource path ([file:/opt/bpf/package/term_model/NetCameraCapture/NetCameraCapture-0.0.1-SNAPSHOT.jar])
解决
1 2 3 4 5
vi /etc/ld.so.conf ------------------- /usr/lib #so包路径 ------------------- ldconfig
For example, on a system with a total of 4GB of RAM the WiredTiger cache will use 1.5GB of RAM (0.5 * (4 GB - 1 GB) = 1.5 GB). Conversely, a system with a total of 1.25 GB of RAM will allocate 256 MB to the WiredTiger cache because that is more than half of the total RAM minus one gigabyte (0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB).
NOTE
In some instances, such as when running in a container, the database can have memory constraints that are lower than the total system memory. In such instances, this memory limit, rather than the total system memory, is used as the maximum RAM available.
To see the memory limit, see hostInfo.system.memLimitMB.
By default, WiredTiger uses Snappy block compression for all collections and prefix compression for all indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation.
Different representations are used for data in the WiredTiger internal cache versus the on-disk format:
Data in the filesystem cache is the same as the on-disk format, including benefits of any compression for data files. The filesystem cache is used by the operating system to reduce disk I/O. Indexes loaded in the WiredTiger internal cache have a different data representation to the on-disk format, but can still take advantage of index prefix compression to reduce RAM usage. Index prefix compression deduplicates common prefixes from indexed fields. Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server. Via the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes.
[root@centos7 container_test]# cat ~/while.sh #!/bin/bash while : ; do : ; done & [root@centos7 container_test]# sh ~/while.sh [root@centos7 container_test]# top
#查看挂载信息 [root@centos7 ~]#cat /proc/self/mountinfo | sed 's/ - .*//'
从上面的结果可以知道PID= 63281其实和PID=1是同一个进程。
mount-手动隔离进程的文件系统
创建一个根文件系统,利用docker的alpine系统创建
1 2 3 4 5 6 7 8 9
[root@centos7 ~]# docker run -it alpine sh #另开一个bash窗口 [root@centos7 ~]# docker ps | grep alpine b8824ba694ab alpine "sh" About a minute ago Up About a minute great_mcnulty [root@centos7 ~]# docker export b8824ba694ab --output=alpine.tar [root@centos7 ~]# mkdir alpine [root@centos7 ~]# tar -xf alpine.tar -C alpine [root@centos7 ~]# ls alpine bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var