简体   繁体   English

“SELECT TOP 1 WITH TIES *”是否在 java sql 连接器中工作?

[英]Does the 'SELECT TOP 1 WITH TIES *', work within java sql connector?

I am developing some code where I want all the max counts displayed to the user.我正在开发一些代码,我希望向用户显示所有最大计数。 Right now in the event of a tie the code will only display one as the max when there is ties.现在,如果出现平局,代码将仅在平局时显示一个作为最大值。 I am just curious how to do this as things I am trying just are not working.我只是好奇如何做到这一点,因为我正在尝试的事情不起作用。

  public static void m() throws SQLException {

       String max = "Select * from table1 order By H DESC";
       ResultSet rs = stmt.executeQuery(max);

       if (rs.next()) {
           String an= rs.getString("an");          
           System.out.println("max: = " + an);

       }
  }

In the SELECT statement I tried to implement SELECT TOP 1 WITH TIES * FROM..... and I get a SQLException error.在 SELECT 语句中,我尝试实现SELECT TOP 1 WITH TIES * FROM.....并且出现SQLException错误。 Also I can get this to work but just enquiring for concise small code.我也可以让它工作,但只是询问简洁的小代码。

For example if animal 1's h is tied with animal 2 and 3's h, it should print all 3 names.例如,如果动物 1 的 h 与动物 2 和 3 的 h 相关联,则应打印所有 3 个名称。 But in this case I wrote above it just prints 1但在这种情况下,我在上面写的它只打印 1

如果你想得到所有的计数,你可以使用这个

 "Select COUNT(*) from table1";
select * from table1 
where h = (select max(h) from table1)

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

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