exists

sql中exists,not exists的用法

醉酒当歌 提交于 2019-11-30 00:47:08
exists : 强调的是是否返回结果集,不要求知道返回什么, 比如: select name from student where sex = 'm' and mark exists(select 1 from grade where ...) ,只要 exists引导的子句有结果集返回,那么exists这个条件就算成立了,大家注意返回的字段始终为1,如果改成“select 2 from grade where ...”,那么返回的字段就是2,这个数字没有意义。所以exists子句不在乎返回什么,而是在乎是不是有结果集返回。 而 exists 与 in 最大的区别在于 in引导的子句只能返回一个字段,比如: select name from student where sex = 'm' and mark in (select 1,2,3 from grade where ...) ,in子句返回了三个字段,这是不正确的,exists子句是允许的,但in只允许有一个字段返回,在1,2,3中随便去了两个字段即可。 而not exists 和not in 分别是exists 和 in 的 对立面。 exists (sql 返回结果集为真) not exists (sql 不返回结果集为真) 下面详细描述not exists的过程: 如下: 表A ID NAME 1 A1 2 A2 3

Linux故障-CentOS7系统firewall报错"Error: INVALID_ZONE"

五迷三道 提交于 2019-11-30 00:03:29
文章目录 系统版本 故障现象 系统日志 分析 相关软件版本 解决办法 可选办法 系统版本 CentOS Linux release 7.1.1503 (Core) 故障现象 [root@server1 ~]$firewall-cmd --list-all Error: INVALID_ZONE [root@server1 ~]$systemctl status firewalld.service firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled) Active: active (running) since 一 2019-05-27 14:33:00 CST; 23h ago Main PID: 5483 (firewalld) CGroup: /system.slice/firewalld.service └─5483 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 5月 27 14:33:00 server1 systemd[1]: Started firewalld - dynamic firewall daemon

sqlalchemy exists for query

爷,独闯天下 提交于 2019-11-29 22:48:29
How do I check whether data in a query exists? For example: users_query = User.query.filter_by(email='x@x.com') How I can check whether users with that email exist? I can check this with users_query.count() but how to check it with exists ? The following solution is a bit simpler: from sqlalchemy.sql import exists print session.query(exists().where(User.email == '...')).scalar() The most acceptable and readable option for me is session.query(<Exists instance>).scalar() like session.query(User.query.filter(User.id == 1).exists()).scalar() which returns True or False . Gary van der Merwe There

is_file or file_exists in PHP

筅森魡賤 提交于 2019-11-29 22:43:50
I need to check if a file is on HDD at a specified location ($path.$file_name). Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP? is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory. So it would depend entirely on your needs. If you want to know specifically if it's a file or not, use is_file() . Otherwise, use file_exists() . Lamy is_file() is the fastest, but recent benchmark shows that file_exists() is slightly faster for me. So

How can you check to see if a file exists (on the remote server) in Capistrano?

霸气de小男生 提交于 2019-11-29 22:43:22
Like many others I've seen in the Googleverse, I fell victim to the File.exists? trap, which of course checks your local file system, not the server you are deploying to. I found one result that used a shell hack like: if [[ -d #{shared_path}/images ]]; then ... but that doesn't sit well with me, unless it were wrapped nicely in a Ruby method. Has anybody solved this elegantly? @knocte is correct that capture is problematic because normally everyone targets deployments to more than one host (and capture only gets the output from the first one). In order to check across all hosts, you'll need

MySQL常见优化

偶尔善良 提交于 2019-11-29 21:35:38
MySQL常见优化 1.操作符优化 1.1<> 操作符(不等于) 1.2LIKE优化 1.3in,not in,exists与not exists 1.3.1in和exists 2.where子句优化 2.1第一个原则:在where子句中应把最具限制性的条件放在最前面。 2.2第二个原则:where子句中字段的顺序应和索引中字段顺序一致。 2.3应尽量避免在 where 子句中使用 or 来连接条件, 2.4应尽量避免在 where 子句中等号的左端对字段进行表达式操作,这将导致引擎放弃使用索引而进行全表扫描。如: 2.5在使用索引字段作为条件时,如果该索引是复合索引,那么必须使用到该索引中的第一个字段作为条件时才能保证系统使用该索引, 3.SQL语句注意事项 3.1在查询中不要使用select * 3.2尽量写WHERE子句 3.3注意SELECT INTO后的WHERE子句 3.4对于聚合查询,可以用HAVING子句进一步限定返回的行 3.5避免使用临时表 3.6减少访问数据库的次数: 3.7尽量少做重复的工作 1.操作符优化 1.1<> 操作符(不等于) 优化原因: 不等于操作符是永远不会用到索引的,因此对它的处理只会产生全表扫描。 优化方法: a): 用其它相同功能的操作运算代替,如 a<>0 改为 a>0 or a<0 a<>'' 改为 a>'' b): 尽量便面使用 !

How to Check if value exists in a MySQL database

老子叫甜甜 提交于 2019-11-29 19:53:13
Suppose I have this table: id | name | city ------------------ 1 | n1 | c1 2 | n2 | c2 3 | n3 | c3 4 | n4 | c4 I want to check if the value c7 exists under the variable city or not. If it does, I will do something. If it doesn't, I will do something else. preferred way, using MySQLi extension: $mysqli = new mysqli(SERVER, DBUSER, DBPASS, DATABASE); $result = $mysqli->query("SELECT id FROM mytable WHERE city = 'c7'"); if($result->num_rows == 0) { // row not found, do stuff... } else { // do other stuff... } $mysqli->close(); deprecated: $result = mysql_query("SELECT id FROM mytable WHERE city =

k8s资源清单配置详解

无人久伴 提交于 2019-11-29 18:38:18
文章目录 一、Pod资源配置 1、非Object配置 2、spec.affinity 2.1、spec.affinity.nodeAffinity 2.2、spec.affinity.podAffinity 2.3、spec.affinity.podAntiAffinity 3、spec.containers 3.1、spec.containers.ports 3.2、spec.containers.env 3.3、spec.containers.volumeMounts 3.4、spec.containers.livenessProbe 3.5、spec.containers.readinessProbe 3.6、spec.containers.resources 3.7、spec.containers.lifecycle 3.8、spec.containers.volumeDevices 4、spec.volumes 4.1、spec.volumes.emptyDir 4.2、spec.volumes.hostPath 4.3、spec.volumes.nfs 4.4、spec.volumes.configMap 4.5、spec.volumes.secret 4.6、spec.volumes.persistentVolumeClaim 4.7、spec.volumes

spring事物传播属性

随声附和 提交于 2019-11-29 17:46:36
PROPAGATION_REQUIRED Support a current transaction; create a new one if none exists. 支持一个当前事务;如果不存在,创建一个新的。 This is typically the default setting of a transaction definition, and typically defines a transaction synchronization scope. 默认设置, 后面的不懂 PROPAGATION_SUPPORTS Support a current transaction; execute non-transactionally if none exists. 支持当前事务;如果不存在当前事务则执行非事务。 PROPAGATION_NOT_SUPPORTED Do not support a current transaction; rather always execute non-transactionally. 不执行当前事务;而是总是执行非事务 PROPAGATION_REQUIRES_NEW Create a new transaction, suspending the current transaction if one exists. 创建一个新的事务

MySQL笔记3

こ雲淡風輕ζ 提交于 2019-11-29 14:44:25
需求:查询员工的姓名和部门名称 A: 笛卡尔积(了解 ) Selet * from A,B; A 2条 B 3条 结果:2*3= 6条 B:内连查询(主外键等值的结果) 表的先后顺序无关 #修改表名 RENAME table 原表名 to 新表名; 1种 where实现内连查询 #查询学生的姓名和班级名称 select s.sname,c.cname from student s,classrom c where s.cid=c.cid; #查询学生的姓名和班级名称 inner JOIN … ON 条件 select s.sname,c.cname from student s INNER JOIN classroom c ON s.cid=c.cid; C.外连接(左外连接 右外连接)和表的先后顺序有关的 左连接:表1 left join 表2 on 条件 以”表1” 作为主表(显示该表中的所有数据,其它没有对应的数据用Null来表示) #显示所有的班级名称信息及对应的学生姓名 select c.cname,s.sname from classroom c LEFT JOIN student s on c.cid=s.cid; #等同于右连接查询 select c.cname,s.sname from student s RIGHT JOIN classroom c on c