any body can help me please? i want to querying from my table, the purpose is to show which employees are selling over 100 pieces. i have done that query and works,
but the problem arises when I want to display the last time of sale of each employee (who sell goods over 100 pieces)
i have table TBL_SALES like
no employee_id name pieces sl_time
---|-------------|-------------|--------|----------
1 | 1 | bungdito | 60 | 2012-03-29 22:20
2 | 1 | bungdito | 40 | 2012-03-05 18:00
3 | 1 | bungdito | 50 | 2012-02-18 08:00
4 | 2 | addheat | 120 | 2012-02-12 09:30
5 | 3 | angga | 20 | 2012-01-18 10:45
6 | 4 | dimas | 50 | 2012-01-01 08:30
when i use query like this
select * from
(
select EMPLOYEE_ID, NAME, sum(PIECES) PIECES from
(
select EMPLOYEE_ID, NAME, PIECES
from DB_SCHEMA.TBL_SALES
)
group by EMPLOYEE_ID, NAME
) where PIECES > 100
i have this correct result
employee_id name pieces
-------------|-------------|--------
1 | bungdito | 150
2 | addheat | 120
the result above is correct,
but what I need is complete with each employees last transaction time
i have tried to make query but still not correct
select * from
(
select EMPLOYEE_ID, NAME, sum(PIECES) PIECES, SL_TIME
(
select EMPLOYEE_ID, NAME, PIECES,(select max(WAKTU) SL_TIME from DB_USER.TR_PELANGGARAN where TB_SALES.EMPLOYEE_ID = EMPLOYEE_ID from TB_SALES) SL_TIME
from DB_SCHEMA.TBL_SALES
)
group by EMPLOYEE_ID, NAME, SL_TIME
) where PIECES > 100
using that query i still have the wrong result (see the sl_time is same between bungdito and addheat) like :
employee_id name pieces sl_time
-------------|-------------|--------|----------
1 | bungdito | 150 | 2012-03-29 22:20
2 | addheat | 120 | 2012-03-29 22:20
what i need is like this below:
employee_id name pieces sl_time
-------------|-------------|--------|----------
1 | bungdito | 150 | 2012-03-29 22:20
2 | addheat | 120 | 2012-02-12 09:30
Try this: