English 中文(简体)
2005年 意见
原标题:SQL Server 2005 Views

下表按有效数据和有效的顺序列出了每名雇员的多个记录: EMPLID, EFFDT, EFFSEQ.

我试图提出一种看法,即我可以具体说明除目前日期外的日期,并取得截至该日期每个雇员的最新记录。 我通常使用的问题是:

SELECT C.EMPLID, C.EFFDT, C.EFFSEQ
  FROM PS_JOB C
 WHERE C.EFFSEQ = (SELECT MAX(INNERALIAS.EFFSEQ)
                     FROM PS_JOB INNERALIAS 
                    WHERE INNERALIAS.EMPLID = C.EMPLID
                      AND INNERALIAS.EFFDT = C.EFFDT)
   AND C.EFFDT = (SELECT MAX(INNERALIAS.EFFDT)
                    FROM PS_JOB INNERALIAS 
                   WHERE INNERALIAS.EMPLID = C.EMPLID
                     AND INNERALIAS.EFFDT <= GetDate())

是否有办法对服务器形成一种看法,在这种看法中,我可以规定一个日期来比较第二个次电文中的?

问题回答

你可以直截了当,但你可以把你的看法同你认为的,并算出一个因你的参数而导致的间谍,并将间谍输出到一张桌上,并在Excel使用该表。





相关问题
How to write this T-SQL WHERE condition?

I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...

Customer and Order Sql Statement

TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...

Recommended way of querying multiple Versioned tables

Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...

update duplicate record

I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...

Define variable to use with IN operator (T-SQL)

I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签