not exists案例
时间: 2023-11-09 11:58:00 浏览: 44
not exists是一个条件语句,用于判断一个查询结果集中是否存在满足指定条件的记录。如果不存在满足条件的记录,则返回true,否则返回false。
在第一个例子中,查询语句select * from A where not exists(select * from B where A.id = B.id)的含义是:从表A中选择所有记录,但是排除那些在表B中存在相同id的记录。
在第二个例子中,查询语句select * from Student st where not exists(select * from Course c where not exists(select * from Score sc where sc.c_id = c.c_id and sc.s_id = st.s_id))的含义是:从Student表中选择所有记录,但是排除那些有某门课程未学习的学生。
相关问题
mysql存储过程案例
以下是一个MySQL存储过程的案例:
```sql
DROP PROCEDURE IF EXISTS getUserInfo;
CREATE PROCEDURE getUserInfo(in date_day datetime)
BEGIN
declare _userName varchar(12); -- 用户名
declare _chinese int; -- 语文
declare _math int; -- 数学
declare done int; -- 定义游标
DECLARE rs_cursor CURSOR FOR SELECT username, chinese, math from userInfo where datediff(createDate, date_day) = 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-- 获取昨天的日期
if date_day is null then
set date_day = date_add(now(), interval -1 day);
end if;
open rs_cursor;
cursor_loop: loop
FETCH rs_cursor into _userName, _chinese, _math; -- 取数据
if done = 1 then
leave cursor_loop;
end if;
-- 更新表
update infoSum set total = _chinese + _math where UserName = _userName;
end loop cursor_loop;
close rs_cursor;
END;
```
这是一个存储过程名为getUserInfo的案例,参数为date_day,日期格式为2008-03-08。在该存储过程中,我们使用游标rs_cursor来查询userInfo表中与指定日期相差一天的记录。然后,我们通过一个循环来遍历游标获取的结果,并更新infoSum表中对应用户名的总分数。该存储过程使用了游标和循环结构来实现对数据的操作。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* *2* [mysql存储过程案例](https://blog.csdn.net/wind_602/article/details/89883323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
boost库函数使用案例
以下是一个使用Boost库中的文件系统(Filesystem)模块的例子,它可以列出给定目录中的所有文件和子目录:
```c++
#include <boost/filesystem.hpp>
#include <iostream>
int main()
{
boost::filesystem::path path_to_list("/path/to/list");
if (boost::filesystem::exists(path_to_list))
{
if (boost::filesystem::is_directory(path_to_list))
{
std::cout << "Contents of directory " << path_to_list << ":" << std::endl;
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
for (boost::filesystem::directory_iterator itr(path_to_list); itr != end_itr; ++itr)
{
std::cout << itr->path().filename() << std::endl;
}
}
else
{
std::cout << path_to_list << " is not a directory" << std::endl;
}
}
else
{
std::cout << path_to_list << " does not exist" << std::endl;
}
return 0;
}
```
在这个例子中,我们首先创建一个 `boost::filesystem::path` 对象 `path_to_list`,它指向我们想要列出文件和子目录的目录。然后我们使用 `boost::filesystem::exists` 函数检查该目录是否存在,如果存在,我们使用 `boost::filesystem::is_directory` 函数检查该路径是否指向一个目录。如果是,我们使用 `boost::filesystem::directory_iterator` 迭代器遍历该目录中的所有文件和子目录,并打印它们的路径名。如果该路径不是一个目录,我们会打印一条错误信息。如果该路径不存在,我们会打印一条不存在的错误信息。