简体   繁体   English

如何更正这种情况表达

[英]How to correct this case expression

I have the following code: 我有以下代码:

select c from(
select 
CASE WHEN EXISTS  (select number, lmn 
  from inma
  WHERE (number='6447' and lmn='ZKZ'))
  then 'yes'
    else 'no' end as c
      from inma )
group by c

I have many number and lmn records in the database, that is why I would like when I run the code to see number and lmn and the result 'yes' (if the number and lmn exist) and 'no' (if they do not exist). 我在数据库中有很多number和lmn记录,这就是为什么我希望在运行代码时看到number和lmn以及结果“是”(如果存在数字和lmn)和“否”(如果它们不存在)存在)。 You can see what I would like to see in the screen shot below. 您可以在下面的屏幕截图中看到我想要看到的内容。

在此处输入图片说明

How I can do this? 我该怎么做? I use PL/SQL developer 我使用PL / SQL开发人员

Thanks for your cooperation in advance. 感谢您的提前配合。

If you want to see those extra fields, then it seems to me that you can just do this: 如果您想查看这些额外的字段,那么在我看来您可以执行以下操作:

SELECT
  i.number,
  i.lmn,
  CASE WHEN i.number='6447' AND i.lmn='ZKZ' THEN
    'yes'
  ELSE 
    'no'
  END AS c
FROM
  inma i

If number and lmn contain duplicates, and you want to hide that, you can use SELECT DISTINCT . 如果number和lmn包含重复项,并且您想将其隐藏,则可以使用SELECT DISTINCT You only need to group by when you are aggregating (eg calculating a sum). 您只需要在汇总时进行group by (例如,计算总和)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM