我想要project_manager列不为空

时间:2015-08-05 12:58:34

标签: sql

查询sql ::我想要project_manager列,它不是null,这是别名。我想让所有查询在project_manager中都为null。我无法获得所需的查询(project_manager为null)。我怎么能得到它?

SELECT T_GPS_APPLICATIONS.APPLICATION_ID,
           T_GPS_APPLICATIONS.APPLICATION_NAME,

        (SELECT u.first_name || ' ' || u.middle_name || ' ' || u.last_name
              from TAS.t_users u, t_gps_app_properties ap
             where to_char(u.user_id) = ap.property_value
               and ap.property_name = 'PROJECT_MANAGER'
               and ap.application_id = T_GPS_APPLICATIONS.application_id)
                                       PROJECT_MANAGER,

           decode(T_GPS_APPLICATIONS.VISIBLE_FLAG,
                  'false',
                  'CLOSED',
                  decode((select count(1)
                           from t_gps_instances gi
                          where gi.application_id =
                                T_GPS_APPLICATIONS.application_id),
                         0,
                         'NOT STARTED',
                         decode((select count(1)
                                  from t_gps_instances       gi,
                                       t_gps_workflow_states ws
                                 where gi.application_id =
                                       T_GPS_APPLICATIONS.application_id
                                   and gi.instance_present = 1
                                   and (gi.active = 1 or gi.active is null)
                                   and gi.current_state_id = ws.state_id
                                   and ws.state_descriptor NOT IN
                                       ('Workflow End', 'AND State')),
                                0,
                                'COMPLETED',
                                'RUNNING'))),

           T_GPS_APPLICATIONS.VISIBLE_FLAG
      FROM STATEGPS.T_GPS_APPLICATIONS   T_GPS_APPLICATIONS,
           STATEGPS.T_GPS_APP_PROPERTIES T_GPS_APP_PROPERTIES
     WHERE T_GPS_APPLICATIONS.APPLICATION_ID =
           T_GPS_APP_PROPERTIES.APPLICATION_ID
       AND (T_GPS_APP_PROPERTIES.PROPERTY_VALUE = 'TRUE' AND 
           T_GPS_APP_PROPERTIES.PROPERTY_NAME = 'PROJECTPLAN_APPLICATION');

          SELECT * FROM   t_gps_app_properties ap;

1 个答案:

答案 0 :(得分:0)

您是否尝试过NOT EXISTS条件?我没有数据库可以尝试......

我冒昧地删除了您的PROJECT_MANAGER列,因为它总是返回NULL

SELECT T_GPS_APPLICATIONS.APPLICATION_ID,
           T_GPS_APPLICATIONS.APPLICATION_NAME,
           decode(T_GPS_APPLICATIONS.VISIBLE_FLAG,
                  'false',
                  'CLOSED',
                  decode((select count(1)
                           from t_gps_instances gi
                          where gi.application_id =
                                T_GPS_APPLICATIONS.application_id),
                         0,
                         'NOT STARTED',
                         decode((select count(1)
                                  from t_gps_instances       gi,
                                       t_gps_workflow_states ws
                                 where gi.application_id =
                                       T_GPS_APPLICATIONS.application_id
                                   and gi.instance_present = 1
                                   and (gi.active = 1 or gi.active is null)
                                   and gi.current_state_id = ws.state_id
                                   and ws.state_descriptor NOT IN
                                       ('Workflow End', 'AND State')),
                                0,
                                'COMPLETED',
                                'RUNNING'))),
           T_GPS_APPLICATIONS.VISIBLE_FLAG
      FROM STATEGPS.T_GPS_APPLICATIONS   T_GPS_APPLICATIONS,
           STATEGPS.T_GPS_APP_PROPERTIES T_GPS_APP_PROPERTIES
     WHERE T_GPS_APPLICATIONS.APPLICATION_ID =
           T_GPS_APP_PROPERTIES.APPLICATION_ID
       AND (T_GPS_APP_PROPERTIES.PROPERTY_VALUE = 'TRUE' AND 
           T_GPS_APP_PROPERTIES.PROPERTY_NAME = 'PROJECTPLAN_APPLICATION')
       AND NOT EXISTS (SELECT u.*
              from TAS.t_users u, t_gps_app_properties ap
             where to_char(u.user_id) = ap.property_value
               and ap.property_name = 'PROJECT_MANAGER'
               and ap.application_id = T_GPS_APPLICATIONS.application_id)