首页 \ 问答 \ SQL QUERY-多个COUNT返回错误(相同)的结果(SQL QUERY- multiple COUNT returns wrong (same) results)

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
更新时间:2019-07-10 12:34

最满意答案

如果您使用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不知道如何对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; ...
  • 你有两个选择: 使您的类实现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> 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 ...
  • 我猜你需要根据值的大小从这个HashMap中创建一个sortedMap。 由于HashMap无法维护排序,我使用LinkedHashMap并使用Java 8(Streams) 。 升序排列: Map> collect = map.entrySet().stream() .sorted((entry1, entry2) -> Integer.compare(entry1.getValue().size(), entry2.ge ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)