我想创建一个复杂的查询,它执行以下操作
得到
laptop
,
service
,
technician
lst
根据笔记本电脑等于X(数字)
在得到的行中,删除
(实际上无法删除,所以请将其
null
)
在同一行中,也许有些没有
技术员
. 所以这些行现在只包含一个
服务
,没有
而且没有
技术员
服务
在那些排里。
如果在世界其他地方找不到它们
桌子,与其他
或
那就去医院
并删除该行。那就回去吧
lst公司
并删除所有具有该属性的行
或
.
lst公司
桌子,搭配其他
笔记本电脑
或
技术员
lst公司
中的行
lst公司
有那个吗
服务
笔记本电脑
技术员
例子
lst table
laptop service technician
17 10 25
17 10 26
17 4 null
17 2 null
125 2 null
我们通过
laptop = 17
变成
laptop service technician
null 10 25
null 10 26
null 4 null
null 2 null
125 2 null
必须删除第3行,因为它没有
技术员
而且没有
笔记本电脑
. 此外,还有
服务
服务
必须删除,因为在
lts
必须删除第4行,因为它没有
而且没有
. 但是
表2
服务
lts公司
笔记本电脑
所以
lts公司
laptop service technician
null 10 25
null 10 26
125 2 null
我只删除
服务
第四部分
服务
桌子
select id , technician from lts where laptop= 17 and technician in(
select id from
lts
where id in
(select id from lts where technician is null and laptop = 17)
);
但是没有什么能起作用,也没有什么能保留所有的ID,并将其从数据库中删除
服务
我想我得用一个
pl/pgsql
服务
桌子。
你知道怎么做吗?战略还是基本准则?
我用的是postgresql10
谢谢