2010prashant
BAN USERSELECT (SUM(e.salary)/COUNT(d.dep_id)) AS Average, d.dep_name, d.dep_id FROM employee e, department d WHERE e.dept_no = d.Dep_id GROUP BY d.dep_id
SELECT AVG(e.salary) AS Average, d.dep_name, d.dep_id FROM employee e, department d WHERE e.dept_no = d.Dep_id GROUP BY d.dep_id
SELECT NAME FROM country WHERE id NOT IN (SELECT c1.id FROM country c1, city c2 WHERE c1.id = c2.Country_id)
SELECT NAME FROM (SELECT c1.name,c1.id, COUNT(c2.name) AS Total FROM country c1 LEFT OUTER JOIN city c2 ON c1.id = c2.Country_id GROUP BY c1.id) AS inner_table WHERE Total < 3
File f = new File("Data.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
List<Integer> sizeList = new LinkedList<Integer>();
List<String> lines = new LinkedList<String>();
String line = null;
//Read from the file and add line to the List.
while ((line = br.readLine()) != null) {
lines.add(line);
sizeList.add(line.length());
}
//Sort the sizeList to get the max length of a line at the last index.
Collections.sort(sizeList);
//Get the value at the last index of the Size List
int largestCharPosition = sizeList.get(sizeList.size() - 1);
int j = 0;
while(j < largestCharPosition) {
for(int i = 0; i < lines.size(); i++) {
int length = lines.get(i).length();
if(length > j) {
System.out.print(lines.get(i).charAt(j));
}
}
System.out.println();
j++;
}
Output :
Val1: 1 Val2: 5
Val1: 2 Val2: 4
Val1: 3 Val2: 3
Val1: 7 Val2: -1
Val1: 8 Val2: -2
//This Works for negative values also
Integer arr[] = {1,2,3,5,6,7,8,9,4,3,3,5,-1,-2};
//Convert the Array to List
List<Integer> list = Arrays.asList(arr);
int sum = 6;
//Take a Map and put the values with their count of occurrence
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i = 0; i < list.size(); i++) {
if(null != map.get(list.get(i))) {
int value = map.get(list.get(i));
map.put(list.get(i), ++value);
}
else {
map.put(list.get(i), 1);
}
}
//Take a Iterator of the List
Iterator<Integer> it = list.iterator();
//Iterate the List
while (it.hasNext()) {
int val = it.next();
int remainVal = sum - val;
//Compare remain value of list with map
if(map.containsKey(remainVal) && map.get(val) < 2) {
System.out.println("Val1: "+val + "Val2: "+remainVal);
//Remove Values from the map so that no repetition is there
map.remove(remainVal);
map.remove(val);
}
if(map.containsKey(remainVal) && map.get(val) >= 2) {
System.out.println("Val11: "+val + "Val22: "+remainVal);
//Remove Values from the map so that no repetition is there
map.remove(remainVal);
map.remove(val);
}
}
public class FileStringTranspose {
public static void main(String[] args) throws IOException {
File f = new File("Data.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
List<Integer> sizeList = new LinkedList<Integer>();
List<String> lines = new LinkedList<String>();
String line = null;
//Read from the file and add line to the List.
while ((line = br.readLine()) != null) {
lines.add(line);
sizeList.add(line.length());
}
//Sort the sizeList to get the max length of a line at the last index.
Collections.sort(sizeList);
//Get the value at the last index of the Size List
int largestCharPosition = sizeList.get(sizeList.size() - 1);
int j = 0;
while(j < largestCharPosition) {
for(int i = 0; i < lines.size(); i++) {
int length = lines.get(i).length();
if(length > j) {
System.out.print(lines.get(i).charAt(j));
}
}
System.out.println();
j++;
}
}
}
SELECT * FROM (SELECT r.name, COUNT(r.id) AS votes FROM persons p, rides r WHERE p.favourite_ride_id = r.id GROUP BY r.id) AS inner_table ORDER BY votes DESC
- 2010prashant September 20, 2013