【问题标题】:disable the last row禁用最后一行
【发布时间】:2011-05-06 02:55:29
【问题描述】:

我在 PostgreSQL 中有这张表:

 appid |               appname               | apptype | creationtime | createdby | display
-------+-------------------------------------+---------+--------------+-----------+---------
     0 | Custom                              |      -1 |              |           | t
  1000 | Performance/Resource                |      -2 |              |           | t
  2000 | PING                                |       0 |              |           | t
  2001 | HTTP                                |       0 |              |           | t
  2002 | HTTPS                               |       0 |              |           | t
  2003 | FTP                                 |       0 |              |           | t
  2004 | LDAP                                |       0 |              |           | t
  2005 | IMAP                                |       0 |              |           | t
  2006 | POP                                 |       0 |              |           | t
  2007 | SMTP                                |       0 |              |           | t
  2008 | DNS                                 |       0 |              |           | t
  2009 | NFS                                 |       0 |              |           | t
  2010 | NTP                                 |       0 |              |           | t
  2011 | SSH                                 |       0 |              |           | t
  2012 | TCP                                 |       0 |              |           | t
  2013 | TELNET                              |       0 |              |           | t
  3000 | Generic Mail (RTT)                  |       3 |              |           | t
  3001 | Apache Tomcat                       |       2 |              |           | t
  3002 | JBoss                               |       2 |              |           | t
  3003 | MySQL                               |       1 |              |           | t
  3004 | WebSphere                           |       2 |              |           | t
  4000 | Microsoft Exchange Server 2003      |       3 |              |           | t
  4001 | Exchange Server 2007 /2010          |       3 |              |           | t
  4003 | Microsoft SQL Server 2008           |       1 |              |           | t
  4004 | Microsoft ISA Server 2006           |      99 |              |           | t
  4005 | Microsoft IIS                       |       4 |              |           | t
  3005 | DB2                                 |       1 |              |           | t
  3006 | Apache HTTP Server                  |       4 |              |           | t
  3007 | Oracle                              |       1 |              |           | t
  3008 | PostgreSQL                          |       1 |              |           | t
  3009 | WebLogic                            |       2 |              |           | t
  3010 | Adobe ColdFusion                    |       2 |              |           | t
  3011 | Sybase                              |       1 |              |           | t
  4007 | Microsoft SQL Server 2005 (EXPRESS) |       1 |              |           | t
  4008 | Microsoft Team Foundation Server    |       2 |              |           | t
  4009 | Microsoft .NET                      |      99 |              |           | t
  3012 | Apache Tomcat                       |       2 |              |           | f

当此表显示在下拉列表中时,Apache Tomcat 重复 2 次。如何禁用最后一行 3012?我有一个删除它的选项,但这个表在几个地方使用,所以我不想删除它。

【问题讨论】:

  • 这里的信息太少了。它可以像“WHERE appid!=3012”一样简单,但谁知道呢?
  • @ceejayoz:当我使用它时,我的整个下拉列表显示为空
  • 我已经在使用这个... $query = "select appid,appname from stat_applications where appid!=0 and appid!=1000";现在我可以把这个放在哪里
  • @ceejayoz: 解决这个问题后也把你的评论放在 ans 我想选择你的 ans 为最佳

标签: php sql postgresql


【解决方案1】:

我认为更重要的问题是为什么它会在您的数据库中出现两次。根据您使用此查询忽略一个查询可能与删除一个查询一样错误。也许这与它是唯一带有显示 f 的条目有关。我想你可以只做 WHERE display != 'f'

【讨论】:

  • $query = "select appid,appname from stat_applications where appid!=0 and appid!=1000";现在我可以把这个放在哪里——
  • 最后 - ... and appid!=1000 and display != 'f'
【解决方案2】:

Tomcat 出现两次,因为它在表中出现两次,一次 ID 为 3001,一次 ID 为 3012。我认为这是数据问题,而不是查询问题。它真的需要在那里两次吗?你说你不愿意删除其中一个,因为它在多个地方使用,但如果你现在不修复它,以后只会更难修复。

我会专注于合并那些重复的行。查找引用这一对中的一个的所有记录(在其他表中),并更新它们以引用另一对。然后你可以删除没有任何引用的那个。

【讨论】:

    【解决方案3】:

    为什么不使用display 列?听起来它是为了过滤掉不应该显示的东西。所以,你可以这样查询:

    SELECT appid, appname
    FROM stat_applications
    WHERE appid  <> 0
      AND appid  <> 1000
      AND display = 't'
    

    如果您不想使用display,那么您可以将 3012 添加到您要忽略的事项列表中:

    SELECT appid, appname
    FROM stat_applications
    WHERE appid  <> 0
      AND appid  <> 1000
      AND appid  <> 3012
    

    或者,由于您的排除列表越来越长,请使用NOT IN

    SELECT appid, appname
    FROM stat_applications
    WHERE appid NOT IN (0, 1000, 3012)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-21
      • 2023-04-06
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多