Select a specific staging record from sybase table

Alpesh003

I have a table with data as below:

Id               stage              date             Emp_id3
=====        =====           =====              =====
DEP1          new             12thmarch         33
DEP1          approval        13thmarch         22
DEP1          reject          14thmarch         77
DEP1          approval        15thmarch         66
DEP1          reject          16thmarch         65
DEP1          approval        17thmarch         87
DEP1          complete        18thmarch         99

I want to find that Emp_id3 who has moved the staging data from reject to approval stage. In this case it will be 87 as it is the latest approval. This is the audit table that has stage wise data for its master table which has current stage data. Can some one please help me with the sybase query for the same? Any help will be much appreciated.

www

The problem you described hits cumber stone Sybase ase issue, no rank function. Bellow I have created a sample solution that involves using of temporary tables. Additional assumption is that date should be in format that ensures uniqueness ( DATETIME should be enough).

CREATE TABLE #temp
(
id VARCHAR(20),
stage VARCHAR(20),
DATE INT,
Emp_id3 INT)

INSERT INTO #temp
 select "DEP1", "new",    12,33
 union select "DEP1", "approval",13,22
 union select "DEP1", "reject", 14,77
 union select "DEP1", "approval",15,66
 union select "DEP1", "reject", 16,65
 union select "DEP1", "approval",17,87
 union select "DEP1", "complete",18,99

SELECT *, rank = identity(1) into #temp_rk FROM #temp ORDER BY DATE

SELECT changer.Emp_id3 FROM 
#temp_rk changer,#temp_rk originator
WHERE
    changer.stage="approval"
    AND originator.stage ="reject"
    AND changer.rank -1 = originator.rank
HAVING changer.rank = max(changer.rank)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Using PHP to select from an SQL table and removing a specific prefix from the results

来自分类Dev

SELECT FROM table,ORDER BY IF(...)

来自分类Dev

Select specific elements from a vector

来自分类Dev

iOS Select specific entries to display in table

来自分类Dev

PHP(“ SELECT * FROM Table WHERE ... AND ...”)

来自分类Dev

如何正确使用Sybase LOAD TABLE?

来自分类Dev

Python 2.7: Select specific character from string

来自分类Dev

LINQ select data from many table

来自分类Dev

SELECT * FROM NEW TABLE在Postgres中等效

来自分类Dev

Assign a value to select list (in a table) from a DB

来自分类Dev

SELECT * FROM MULTIPLE + DYNAMIC table_name

来自分类Dev

从SELECT * FROM $ table中排除字段

来自分类Dev

mysql select * from table group by id with rollup

来自分类Dev

MySQL SELECT FROM 3 Table with where

来自分类Dev

提高查询速度:简单的SELECT from SELECT in large table

来自分类Dev

select * from table where id = select max id in codeigniter

来自分类Dev

“ NOT IN table.col”和“ NOT IN SELECT col FROM table”之间的区别

来自分类Dev

How to select servers that does not have a date record in a separate table between a date range?

来自分类Dev

Sybase存储过程中的SELECT和TRUNCATE

来自分类Dev

Sybase和null字符串在select中。奇怪的处理

来自分类Dev

Select field from table A where subselect from table B = table A field

来自分类Dev

使用staging_table1和table2中的数据插入table1,同时使用staging_table1从table2中获取数据

来自分类Dev

使用staging_table1和table2中的数据插入table1,同时使用staging_table1从table2中获取数据

来自分类Dev

How do I copy data from each record of one table into multiple records of another table related to the first table?

来自分类Dev

MySQL SELECT * FROM table1,table2,table3

来自分类Dev

mysql insert into, select from other table while altering data

来自分类Dev

“ SELECT * FROM database..table”中的“ ..”是什么意思?

来自分类Dev

SELECT encrypted items from a table using LIKE on an expression

来自分类Dev

SELECT * FROM table WHERE MONTH =今天的下个月

Related 相关文章

  1. 1

    Using PHP to select from an SQL table and removing a specific prefix from the results

  2. 2

    SELECT FROM table,ORDER BY IF(...)

  3. 3

    Select specific elements from a vector

  4. 4

    iOS Select specific entries to display in table

  5. 5

    PHP(“ SELECT * FROM Table WHERE ... AND ...”)

  6. 6

    如何正确使用Sybase LOAD TABLE?

  7. 7

    Python 2.7: Select specific character from string

  8. 8

    LINQ select data from many table

  9. 9

    SELECT * FROM NEW TABLE在Postgres中等效

  10. 10

    Assign a value to select list (in a table) from a DB

  11. 11

    SELECT * FROM MULTIPLE + DYNAMIC table_name

  12. 12

    从SELECT * FROM $ table中排除字段

  13. 13

    mysql select * from table group by id with rollup

  14. 14

    MySQL SELECT FROM 3 Table with where

  15. 15

    提高查询速度:简单的SELECT from SELECT in large table

  16. 16

    select * from table where id = select max id in codeigniter

  17. 17

    “ NOT IN table.col”和“ NOT IN SELECT col FROM table”之间的区别

  18. 18

    How to select servers that does not have a date record in a separate table between a date range?

  19. 19

    Sybase存储过程中的SELECT和TRUNCATE

  20. 20

    Sybase和null字符串在select中。奇怪的处理

  21. 21

    Select field from table A where subselect from table B = table A field

  22. 22

    使用staging_table1和table2中的数据插入table1,同时使用staging_table1从table2中获取数据

  23. 23

    使用staging_table1和table2中的数据插入table1,同时使用staging_table1从table2中获取数据

  24. 24

    How do I copy data from each record of one table into multiple records of another table related to the first table?

  25. 25

    MySQL SELECT * FROM table1,table2,table3

  26. 26

    mysql insert into, select from other table while altering data

  27. 27

    “ SELECT * FROM database..table”中的“ ..”是什么意思?

  28. 28

    SELECT encrypted items from a table using LIKE on an expression

  29. 29

    SELECT * FROM table WHERE MONTH =今天的下个月

热门标签

归档