通过计算领域来选择

时间:2015-12-01 19:10:06

标签: mysql sql firebird

让我们假设我们有一个子查询查询:

SELECT     
    K.NAME,      
     (  SELECT 
         COUNT(*)      
       FROM          
       "001INSIDE_PROCEDURE"     
       ('PARAM1','PARAM2', K.ID, 1) S     ) AS MY_NUMBER,             
FROM
 "001CLIENTS" K   WHERE           
 (K.ACTIVE = 1)  ORDER BY                                
K.NAME

它工作正常,我已经获得了MY_NUMBER列。 我想要有可能性 WHERE(K.ACTIVE = 1)和MY_NUMBER = 10 换句话说:是否有机会通过计算查询中的列来进行选择?

罗伯特

1 个答案:

答案 0 :(得分:0)

您可以简单地添加另一个where子句,如下所示。

      SELECT     
        K.NAME,      
         (  SELECT 
             COUNT(*)      
           FROM          
           "001INSIDE_PROCEDURE"     
           ('PARAM1','PARAM2', K.ID, 1) S     ) AS MY_NUMBER             
    FROM
     "001CLIENTS" K
   WHERE           
     (K.ACTIVE = 1) 
    and (  SELECT 
             COUNT(*)      
           FROM          
           "001INSIDE_PROCEDURE"     
           ('PARAM1','PARAM2', K.ID, 1) S) =  10 
  ORDER BY                                
    K.NAME