SQL QUERY-多个COUNT返回错误(相同)的结果(SQL QUERY- multiple COUNT returns wrong (same) results)
如何结合这两个查询而不给我相同的输出?
第一个查询是:
select vwemployee.directorateName , count(vwemployeeCourse.employeeId) as t1 from vwemployee , vwemployeeCourse where vwemployee.directorateName = vwemployeeCourse.directorateName GROUP BY vwemployee.directorateName
这是第二个查询:
select vwemployee.directorateName , count(vwemployee.directorateName) as t2 from vwemployee , employeeCourse where vwemployee.Id = employeeCourse.employeeId GROUP BY vwemployee.directorateName
我将使用组合查询生成报告
第一栏是董事会的名称
顺便说一下,当我把它们结合起来时,我的自我t1和t2有相同的结果但是当它们分开时它给了我正确的结果
t1栏应该显示这个特定董事会的课程数量,而t2栏应该显示这个董事会下这个课程的人数
因此,组合查询的表的总列数应为3列
how to combine this two queries without giving me the same output ?
the first query is :
select vwemployee.directorateName , count(vwemployeeCourse.employeeId) as t1 from vwemployee , vwemployeeCourse where vwemployee.directorateName = vwemployeeCourse.directorateName GROUP BY vwemployee.directorateName
this is the second query :
select vwemployee.directorateName , count(vwemployee.directorateName) as t2 from vwemployee , employeeCourse where vwemployee.Id = employeeCourse.employeeId GROUP BY vwemployee.directorateName
i will be using the combined query to generate a report
the first column is the name of the directorate
by the way when i combined them my self t1 had the same result as t2 but when they are separate it gave me the right result
the t1 column should display how many courses this specific directorate took , and t2 column should display how many employee's under this directorate took this courses
so the total columns of the table of the combined query should be 3 columns
原文:https://stackoverflow.com/questions/37185395
最满意答案
如果您使用Java 8进行开发,则可以使用lambda表达式:
Collections.sort(membersArrayList, (m1, m2) -> (int) (m2.getMemberID() - m1.getMemberID()));
You might use lambda expression if you are developing in Java 8:
Collections.sort(membersArrayList, (m1, m2) -> (int) (m2.getMemberID() - m1.getMemberID()));
相关问答
更多-
我可以简单地使用TreeSet对ArrayList的ArrayList进行排序吗?(Can I sort ArrayList of ArrayList simply by using TreeSet?)[2024-02-09]
TreeSet不知道如何对ArrayLists进行排序,因为列表没有自然排序。 它应该将列表与值的最小值,列表的平均值或其他值进行比较吗? 要使TreeSet了解您要排序的内容,您必须向构造函数添加一个比较器: TreeSet> hs = new TreeSet<>(comparator); 比较器必须实现Interface Comparator 。 在这里您可以定义如何订购ArrayList。 如果不添加比较器,TreeSet会隐式地期望Arr ... -
如果您使用Java 8进行开发,则可以使用lambda表达式: Collections.sort(membersArrayList, (m1, m2) -> (int) (m2.getMemberID() - m1.getMemberID())); You might use lambda expression if you are developing in Java 8: Collections.sort(membersArrayList, (m1, m2) -> (int) ...
-
你想要做的是首先在a中添加一些内容因为你总是在外部列表上读取i值,所以我们在外部循环上添加一个新的数组列表。 import java.util.ArrayList; public class abc { public static void main(String[] args) { ArrayList
> a = new ArrayList >(); for(int i=0;i<10; ... -
ArrayLIst的排序(Sorting of ArrayLIst)[2022-09-27]
你有两个选择: 使您的类实现Comparable ,并在不指定比较器的情况下调用Collections.sort 正确实施比较器 你好像采取了“我试过X并且它不起作用的方法,因此我需要尝试别的东西” - 但X(使用比较器)不起作用的原因似乎是你的比较器有错误。 ..它没有以你想要的方式比较项目。 实现Comparable时,您将遇到完全相同的问题。 你还有相同的基础工作要做(弄清楚如何比较两个项目) - 这实际上只是逻辑在哪里。 通常,实现Comparator是一种更灵活的方法,因为它允许根据您的需要以不同 ... -
该参数决定ArrayList的起始容量。 ArrayList内部分配内存以容纳一定数量的对象。 当你添加更多元素时,它必须分配更多内存并将所有数据复制到新位置,这需要一些时间。 因此,您可以指定要在ArrayList放置多少个对象来猜测Java。 起始大小0可能表示程序员认为ArrayList很少被使用,因此不需要为它开始分配内存。 [编辑] 为了澄清,正如@LuiggiMendoza和@emory在讨论中所说的那样,很难想象使用0作为初始容量是有意义的。 在大多数情况下,默认构造函数工作得很好。 The ...
-
假设您已经有一个ArrayList
>初始化; 我们将其称为list 。 您必须传递一个自定义Comparator >来对每个TreeSet 进行排序: Collections.sort(list, Comparator.comparing(TreeSet::first)); 根据每个TreeSet 的第一个元素,按升序排序ArrayList > 。 Let's say that ... -
试试这个:我已经添加了解释我修改了修补程序的注释。 希望能帮助到你 :) import java.util.ArrayList; public class Sorting { public static void main(String[] args) { ArrayList
alInput = makeArray(5); // now you can get the sorted string :) String ... -
在ArrayList
>中添加整数(Add Integer in ArrayList [2023-07-10]>) ArrayList> player = new ArrayList >(10); ArrayList array = new ArrayList (10); array.add(1); array.add(2); array.add(3); array.add(4); array.add(5); ArrayList array1 = new ArrayList (ar ... -
自定义比较器cmp刚刚分配了按降序对list进行排序的任务 Comparator
cmp = new Comparator () { @Override public int compare(Integer o1, Integer o2) { if (o1 < o2) { return 1; } else { return -1; } } }; Coll ... -
对基于ArrayList大小映射到ArrayList的HashMap进行排序(Sort HashMap that maps to ArrayList based on ArrayList size)[2023-09-25]
我猜你需要根据值的大小从这个HashMap中创建一个sortedMap。 由于HashMap无法维护排序,我使用LinkedHashMap并使用Java 8(Streams) 。 升序排列: Map> collect = map.entrySet().stream() .sorted((entry1, entry2) -> Integer.compare(entry1.getValue().size(), entry2.ge ...