Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 使用Select查询时的Postgres_Postgresql_Postgresql 9.3 - Fatal编程技术网

Postgresql 使用Select查询时的Postgres

Postgresql 使用Select查询时的Postgres,postgresql,postgresql-9.3,Postgresql,Postgresql 9.3,我有一个Postgres当案例查询错误。我如何修复该查询 SELECT CASE WHEN AccountStatus='Open' THEN ( SELECT * from Accounts where statusID=1 ) WHEN AccountType='Mutual'

我有一个Postgres当案例查询错误。我如何修复该查询

SELECT CASE
            WHEN  AccountStatus='Open' 
           THEN
             (
              SELECT  * 
               from Accounts
               where statusID=1
             )

        WHEN  AccountType='Mutual'
           THEN
             (
               SELECT *
               FROM Accounts
               WHERE AccountTypeID=2
             )

   END as Status, *
FROM Accounts
显示错误:

由用作表达式的子查询返回的多行


我认为您的问题不是案例查询,您希望得到如下所示的表行。如果您确实想在类型查询时使用
case,请详细定义表

SELECT *, 'Open' AS Status from Accounts where statusID = 1
UNION ALL
SELECT *, 'Mutual' AS Status FROM Accounts WHERE AccountTypeID = 2 
你应该试试这个:-

SELECT *
FROM Accounts
WHERE CASE  WHEN (AccountStatus='Open' ) THEN statusID=1 
            WHEN (AccountType='Mutual')THEN AccountTypeID=2 
      END;

请提供表的详细信息。这两个子查询位于查询的SELECT部分,因此只能返回一个值。我怀疑您的
账户
表中有多条记录的
StatusID=1
StatusID=2
。您如何怀疑它会在结果集中的一条记录中显示多条记录?如果你分享一些样本数据和你想要的结果,我们可以引导你找到一种获得你想要的东西的正确方法。