使用Oracle SQL进行复杂计算(Complicated Calculation Using Oracle SQL)
我为虚构的律师创建了一个数据库,我最后一次要完成的查询让我疯狂。 我需要计算一名律师在公司的职业生涯中所取得的总人数,我有
time_spent
和rate
来增加乘数和特殊费率。 (特殊费率是公司合同的一次性费用,所以很少有这种费用)。 我能想到的最好的代码如下。 它做我想要的,但只显示工作在一个案件与特殊的速度适用于它的律师。我基本上希望它能够在表中显示查询结果,即使特殊比率为NULL。
我已经订购了表格以显示最高金额,因此我可以使用ROWNUM仅显示前10%的收款人。
CREATE VIEW rich_solicitors AS SELECT notes.time_spent * rate.rate_amnt + special_rate.s_rate_amnt AS solicitor_made, notes.case_id FROM notes, rate, solicitor_rate, solicitor, case, contract, special_rate WHERE notes.solicitor_id = solicitor.solicitor_id AND solicitor.solicitor_id = solicitor_rate.solicitor_id AND solicitor_rate.rate_id = rate.rate_id AND notes.case_id = case.case_id AND case.contract_id = contract.contract_id AND contract.contract_id = special_rate.contract_id ORDER BY -solicitor_made;
查询:
SELECT * FROM rich_solicitors WHERE ROWNUM <= (SELECT COUNT(*)/10 FROM rich_solicitors)
I have created a database for an imaginary solicitors, my last query to complete is driving me insane. I need to work out the total a solicitor has made in their career with the company, I have
time_spent
andrate
to multiply and special rate to add. (special rate is a one off charge for corporate contracts so not many cases have them). the best I could come up with is the code below. It does what I want but only displays the solicitors working on a case with a special rate applied to it.I essentially want it to display the result of the query in a table even if the special rate is NULL.
I have ordered the table to show the highest amount first so i can use ROWNUM to only show the top 10% earners.
CREATE VIEW rich_solicitors AS SELECT notes.time_spent * rate.rate_amnt + special_rate.s_rate_amnt AS solicitor_made, notes.case_id FROM notes, rate, solicitor_rate, solicitor, case, contract, special_rate WHERE notes.solicitor_id = solicitor.solicitor_id AND solicitor.solicitor_id = solicitor_rate.solicitor_id AND solicitor_rate.rate_id = rate.rate_id AND notes.case_id = case.case_id AND case.contract_id = contract.contract_id AND contract.contract_id = special_rate.contract_id ORDER BY -solicitor_made;
Query:
SELECT * FROM rich_solicitors WHERE ROWNUM <= (SELECT COUNT(*)/10 FROM rich_solicitors)
原文:https://stackoverflow.com/questions/5172230
最满意答案
感谢您对该问题的更新。 这里有一些代码,我相信你正在寻找的东西。
public static String printDots(int numDots) { String dots = ""; for(int i = 0; i < numDots; i++) { dots += "."; } return dots; } public static void main(String[] args) { String[][] matrix = new String[10][10]; int numDots = 4; for (int i = 0; i < matrix.length; i++) { for(int j = 0; j < matrix[i].length; j++) { matrix[i][j] = printDots(numDots); } if(i%2 != 0) numDots--; } for(int i = 0; i < matrix.length; i++) { for(int j= 0; j < matrix[i].length; j++) System.out.println(matrix[i][j]); } } }
Thanks for the update on the question. here is some code that I believe does what you are looking for.
public static String printDots(int numDots) { String dots = ""; for(int i = 0; i < numDots; i++) { dots += "."; } return dots; } public static void main(String[] args) { String[][] matrix = new String[10][10]; int numDots = 4; for (int i = 0; i < matrix.length; i++) { for(int j = 0; j < matrix[i].length; j++) { matrix[i][j] = printDots(numDots); } if(i%2 != 0) numDots--; } for(int i = 0; i < matrix.length; i++) { for(int j= 0; j < matrix[i].length; j++) System.out.println(matrix[i][j]); } } }
相关问答
更多-
如果你只想要一个数组的“调试风格”转储: String str = Arrays.toString(arr); 或者,为了更多的控制(在Java 8之前): StringBuilder builder = new StringBuilder(); for(String s : arr) { builder.append(s); } String str = builder.toString(); (Java 8及更高版本): String str = String.join(",", arr); ...
-
你传递一个对象数组,所以你不能从这个数组中获取字符。 一种方式是这样的: int size = env->GetArrayLength(stringArrays); for (int i=0; i < size; ++i) { jstring string = env->GetObjectArrayElement(stringArrays, i); const char* mayarray = env->GetStringUTFChars(string, 0); .... do ...
-
数组具有固定的大小,因此向数组添加元素并不容易。 您想要的行为正是java.util.Set的行为。 学习如何使用标准集合:它们比数组更强大。 如果要保留元素的顺序,请使用LinkedHashSet。 请参阅http://download.oracle.com/javase/tutorial/collections/ 。 现在,为什么你的代码失败了? 您正在迭代数组,一旦找到一个不等于字符串的元素,就用字符串替换它。 而且你也可以在不考虑数组长度的情况下进行迭代。 这是您可能想要的代码: boolean f ...
-
感谢您对该问题的更新。 这里有一些代码,我相信你正在寻找的东西。 public static String printDots(int numDots) { String dots = ""; for(int i = 0; i < numDots; i++) { dots += "."; } return dots; } public static void main(String[] args) { ...
-
比较java中的字符串(comparing strings in java)[2024-01-22]
int x = 0; int i= 0; int j = 0; while(i != list1.length && j != list2.length){ int v = list1[i].compareTo(list2[j]); if (v == 0){ x++;i++;j++; }else if (v < 0){ i++; } else { j++; } } return x; 这使得直截了当地假设字符串使用String.compareTo进行排序,这是 ... -
将字符串存储到数组中?(Storing strings into an array?)[2023-06-17]
String[] name = str.split(','); String[] name = str.split(','); -
在数组上操作字符串(Manipulating Strings on Arrays)[2023-04-06]
正则表达式对您来说非常方便。 代码bellow可以做,你的工作使用正则表达式: String mainStr = "ABBCCCBBAA"; Pattern p = Pattern.compile("(AA)|(BB)|(BA)|(AB)|(CC)|(BC)"); Matcher m = p.matcher(mainStr); while (m.find()) { String matchedStr = m.group(0); if("AA ... -
Pattern p = Pattern.compile("\\((.*?)\\)"); Matcher m = p.matcher("abc (one) abc (two) abc"); List
result = new ArrayList (); while(m.find()) result.add(m.group(1)); Pattern p = Pattern.compile("\\((.*?)\\)"); ... -
我看到你读了两次data.txt并且根本没有使用第一个读取结果。 我不明白,你想用String做什么,但是有二维数组并计算int的列总和很容易: public class Array_2D { static final class Item { final String str; final int val1; final int val2; Item(String str, int val1, int val2) { ...
-
如果您想要一个简短的示例,您可以执行以下操作 String[] array = ... String asString = Arrays.toString(array); if(asString.equals(asString.toLowerCase()) // no upper case characters. If you want a short example, you could do the following String[] array = ... String asString = ...