Posts

Showing posts from August, 2016

Will DISTINCT always return a same order of values for a same SQL?

I have a sql statement is with pattern SELECT id FROM table WHERE [conditions] ORDER BY [orders] LIMIT 10000 OFFSET 0 and the return value is like below: id ----- 1 0 0 0 0 1 1 1 2 2 ... Then I want to get the distinct value as the order of their first appearance, since there's an ORDER BY in the sql, and DISTINCT or GROUP BY are both happened before ORDER BY in a sql, I tried below sql. SELECT DISTINCT id FROM ( SELECT id FROM table WHERE [conditions] ORDER BY [orders] LIMIT 10000 OFFSET 0 ) tmp; And the result is like what I want: id ---- 1 0 2 ... My question is: can I ensure that in a same pattern SQL, DISTINCT will always return the distinct id as the order their first appearance? Thanks. ---------------Notes------------------ Below can be ignored. I just noticed many peoples are recommended to try GROUP BY, so I tried below sql as well: SELECT id FROM ( SELECT

Table not found in statement

Class . forName ( "org.hsqldb.jdbcDriver" ); conn = DriverManager . getConnection ( "jdbc:hsqldb:file:Pokemondaten" , "sa" , "" ); getData = conn . createStatement (); ResultSet rs = getData . executeQuery ( "SELECT HP FROM PKMN WHERE ID = " + basicnumber ); int hpp = rs . getInt ( 1 ); System . out . println ( hpp ); all I get is java . sql . SQLException : Table not found in statement [ SELECT HP FROM PKMN ] at org . hsqldb . jdbc . Util . sqlException ( Unknown Source ) at org . hsqldb . jdbc . jdbcStatement . fetchResult ( Unknown Source ) at org . hsqldb . jdbc . jdbcStatement . executeQuery ( Unknown Source ) at pokeWpRechner . Main . main ( Main . java : 46 ) My Databased is called  Pokemondaten and my table is called  PKMN , also my table is inherited in the programm. So what did i do wrong? i dont get it. Hi Ekonion,  You are facing above problem.You may

how to sum the value for a selective condition in mysql

my table is id month amount 1 mar 100 1 apr 100 2 mar 200 2 apr 200 3 mar 300 3 apr 300 I need the out put as id amount 1 200 2 400 3 600 so pls give the query how to wrrite it Hi , It is basic Concept inside Group By here is your code SELECT id,Sum(amount)FROM mytable Group By amount

How do i iterate through this arraylist ?

I'm relatively new to programming. I'm trying to teach myself Java, and I'm messing around with   ArrayLists . How do I go about printing each of these strings individually? Right now, I have it where it prints each list, but I want to be able to work with each string individually. Like if I wanted to print out the length of each string using a for loop how would I do that? I tried doing the standard for loop, but I couldn't figure out what to put for the termination requirement. I tried   i < 2   since   test[3]   is length 2, but that gave an out of bounds error since the other test lists only have one element. public static void main( String [] args) {   int arrlen = 4 ;   ArrayList [] test = new ArrayList [arrlen];   for ( int i= 0 ; i<arrlen; i++)   {     test[i] = new ArrayList < String >();   }   test[ 0 ].add( "zero" );   test[ 1 ].add( "one" );   test[ 2 ].add( "two" );   test[ 3 ]

How can I use java Integer.parseInt()?

     Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string:         "00001                        "      at java.lang.NumberFormatException.forInputString(Unknown Source)      at java.lang.Integer.parseInt(Unknown Source)      at java.lang.Integer.parseInt(Unknown Source)      at LibraryManager.BookAdd.getInsertOrderedList(BookAdd.java:105) while(rs1.next()){             allid[i]=rs1.getString("id");             String mystr=allid[i].substring(1);             try{             System.out.println(mystr);//this print 00001             intofid[i]=Integer.parseInt(mystr);             }catch(Exception e){                 e.printStackTrace();             }             i++;         }     how could I resolved this??    Hey Hiro ,    Here is complete solution of your problem.It is basic concept but important concept inside String.    String var ="A00001";    int vars=

designinghub