用户排序的同一个表中的多个查询无法正常工作 [英] Multiple Queries from the same table ordered by user not working

查看:79
本文介绍了用户排序的同一个表中的多个查询无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,


所以我使用SQL比较新,或者至少从我大学时代起就没用过它因此似乎无法获得工作非常基础的东西。


我有一个名为TRACKING_TRAIN的表来跟踪一个用户的所有活动。每个活动都分配了一个代码。该表捕获事务代码,完成时间以及执行事务的用户名。


我试图将这些信息的一些部分拉成1个表作为通过某一天的行动次数来衡量某人的生产力的一种手段。


我希望我的桌子看起来像什么的例子


行动1 |行动2 |行动3 |

--------------------------------------- ---

约翰| 34 | 2 | 4 |

莎拉| 2 | 2 | 3 |


因为所有动作都不同我正在使用3个不同的查询。第一个拉取user_ID并使用操作1计算触摸的项目数,并按User_ID对其进行分组。那部分工作正常。一旦我添加了我的其他查询,我真的不知道如何合并它们,所以我得到了名称字段的重复结果。


这里是我的代码示例:

Hey,

So i''m relatively new to using SQL, or at least haven''t used it since my college days and therefor can''t seem to get something pretty basic to work.

I have ONE table called TRACKING_TRAIN that tracks all activities from one user. Each activity is assigned a code. The table captures the transaction code, the time it was done, and the username of who did the transaction.

I''m trying to pull bits and pieces of this information into 1 table as a means of measuring someones productivity by the number of actions on a certain day.

Example of what I want my table to look like

Name | Action 1 | Action 2 | Action 3 |
------------------------------------------
John | 34 | 2 | 4 |
Sarah | 2 | 2 | 3 |


Because all actions are a different I''m using 3 different queries. The first pulls the user_ID and counts the number of items that were touched using Action 1, grouping it by User_ID. That part works fine. Once I add my additional queries I don''t really know how to merge them so I get duplicate results of the name field.

Here''s an example of my code:

展开 | 选择 | Wrap | 行号

推荐答案

你应该将它们联合起来然后进行计数。不要单独计算每个,然后将它们联合起来。
You should union them all and then do the count. Not count each separately and then union them.


但它们都来自同一个表并转到同一个表。动作ID号都来自同一列。那有意义吗?我错过了一些非常明显的东西。
But they''re all from the same table and going to the same table. The action id numbers all come from the same column. Does that make sense? I''m missing something pretty obvious somewhere.


我现在很困惑。查看样本输入数据和生成的输出数据会有所帮助。
I''m just confused now. It would help to see sample input data and resulting output data.


这篇关于用户排序的同一个表中的多个查询无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆