我有2个表,其中包含逗号分隔值的列,我想计算该列的所有相同值,这里是示例表:
import java.util.Scanner;
public class SerialCheck{
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("How many serial numbers would you like to check: ");
int length = sc.nextInt();
int valid = 0;
String[] sSerials = new String[length];
for (int nCtr = 0; nCtr < length; nCtr++){
System.out.print ("Enter Serial " + (nCtr+1) + ": ");
sSerials[nCtr] = sc.next();
}
System.out.println();
System.out.println("The following were added: ");
for(int nCtr = 0; nCtr < length; nCtr++){
System.out.println(sSerials[nCtr]);
}
System.out.println();
for(int nCtr = 0; nCtr < length; nCtr++){
for (int x = 0; x < sSerials[nCtr].length(); x++){
char c = sSerials[nCtr].charAt(x);
if((sSerials[nCtr].charAt(x)!='a') ||
(sSerials[nCtr].charAt(x)!='b') ||
(sSerials[nCtr].charAt(x)!='c') ||
(sSerials[nCtr].charAt(x)!='-') ||
(sSerials[nCtr].charAt(x)!='.')){
valid--;
}
else{
valid++;
}
}
if (valid < 0 && sSerials[nCtr].length() != 14){
System.out.println("The address is invalid.");
}
else{
System.out.println("The address is valid.");
}
}
}
}
现在,您有任何想法或建议,以便我能实现吗?比如添加新表或者单个查询是否可以这样做?
答案 0 :(得分:0)
尝试此查询
SELECT LENGTH(COLUMN) - LENGTH(REPLACE(COLUMN, ',', '')) FROM TABLE_NAME