English 中文(简体)
分区发生的数量
原标题:Counting number of occurrences in subquery

我的任务是在我们的数据库中找到每个雇员迟交的时间单的数量。 我主要研究的是两个表格,但我有麻烦地把这两张表格放在一起,并带着对“<条码>(COUNT<>>)的正确看法和与这些表格相关的雇员身份。

我设立了这个问询,向我提供<代码>。 每一次雇员:

SELECT db.Employee.EmployeeID 
FROM db.LateTimesheets
INNER JOIN db.Employee ON Employee.LastName = LateTimesheets.LastName AND Employee.FirstName = Late Timesheets.FirstName

现在,鉴于这一简单问题,我对<代码>的看法。 多次发生这种事件。 然而,我最终要总结的是一张表,显示每个事件的计数以及<代码>。 EmployeeID, 与此相关。

我假定,我需要使用<条码>(COUNT)功能,以计算每个条码的浏览量。 EmployeeID, 然后与一道选择这一数值。 EmployeeID。 然而,我正在设法正确安排分局,而我迄今为止所尝试的一切只是给MSQ服务器管理室造成错误。

问题回答

A simpler version of usr s answer would be the following which avoids the construction of the derived table:

Select db.Employee.EmployeeID, Count( db.LateTimesheets.somecolumn ) As Total
From db.Employee 
    Left Join db.LateTimesheets
        On LateTimesheets.LastName  = Employee.LastName
            And Late Timesheets.FirstName = Employee.FirstName
Group By db.Employee.EmployeeID

我可能误解了这个问题,但将登t 。 按分类 解决你的问题?

SELECT COUNT(db.LateTimesheets.somecolumn), db.Employee.EmployeeID 
FROM db.LateTimesheets
INNER JOIN db.Employee ON Employee.LastName = LateTimesheets.LastName 
    AND Employee.FirstName = Late Timesheets.FirstName
GROUP BY db.Employee.EmployeeID

Just replace somecolumn with the name of a column that s actually in the table.

select e.*, isnull(lt.Count, 0) as Count
from Employee e
left join (
 select LastName, count(*) as Count from LateTimesheets
) LateTimesheets lt on e.LastName = lt.LastName

陷阱是将这种分类纳入一个衍生表。 你们不想把一切混为一谈,而只是时间晚。

我们需要一个休息点,才能让雇员拿不晚餐。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签