SELECT count(*)然后输出空或不为空,是或否

编程入门 行业动态 更新时间:2024-10-17 09:47:08
本文介绍了SELECT count(*)然后输出空或不为空,是或否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

查找SALES部门的位置与TRANSPORT部门在完全相同的城市中"(假设空结果表示YES,任何非空结果表示NO)

Find if SALES department has its locations in exactly the same cities as TRANSPORT department"(assume that an empty result means YES and any nonempty result means NO)

在我的数据库中有此表.

In my database got this table.

//DEPTLOC DNAME CITY ---------------- SALES LONDON TRANSPORT LONDON TRANSPORT BOSTON SCIENCE BOSTON

不确定如何编写查询,但至少我会尝试

Not sure how to write the query but at least i try

SELECT COUNT(*) FROM DEPTLOC WHERE (DNAME='SALES' AND DNAME='TRANSPORT') AND

我应该如何在AND运算符之后编写sql以获得类似这样的输出

How should i write after the AND operator in sql in order to get output something like this

//Display YES . (<--- LONDON , got SALES and TRANSPORT in same cities)

推荐答案

您可以使用解码

SELECT Decode(Count(*), 0, 'No', 'Yes') FROM {rest of your query}

DECODE将expr与每个搜索值一一比较.如果expr等于搜索,则Oracle数据库返回相应的结果.如果找不到匹配项,则Oracle返回默认值.如果省略默认值,则Oracle返回null.

DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.

更多推荐

SELECT count(*)然后输出空或不为空,是或否

本文发布于:2023-11-02 14:17:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:或不   为空   SELECT   count

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!