alexa-tracking

[Tanya SQL Query] Cara Group berdasarkan order

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/53d23101dc06bd12238b45ff/tanya-sql-query-cara-group-berdasarkan-order
[Tanya SQL Query] Cara Group berdasarkan order
Hi, mau tanya nih aga sedikit tricky:

Misalkan gua punya table kaya gini:

name , date_transaction
-------------------------------------
jojo, 2014-1-1 00:01
jojo, 2014-1-1 00:02
jojo, 2014-1-1 00:03
jame, 2014-1-1 00:04
jame, 2014-1-1 00:05
jame, 2014-1-1 00:06
soso, 2014-1-1 00:07
soso, 2014-1-1 00:08
soso, 2014-1-1 00:09
jojo, 2014-1-1 00:10
jojo, 2014-1-1 00:11
jojo, 2014-1-1 00:12
soso, 2014-1-1 00:13
soso, 2014-1-1 00:14
soso, 2014-1-1 00:15

nah, gua mau hasilnya tuh di group, tapi berdasarkan order dari date_transaction seperti ini hasilnya:

name, start_date, end_date
---------------------------------------------------
jojo, 2014-1-1 00:01, 2014-1-1 00:03
jame, 2014-1-1 00:04, 2014-1-1 00:06
soso, 2014-1-1 00:07, 2014-1-1 00:09
jojo, 2014-1-1 00:10, 2014-1-1 00:12
soso, 2014-1-1 00:13, 2014-1-1 00:15

Kira2 bisa ga ya kalo begini hasilnya?

Master2 SQL pls help

Thanks
Quote:Original Posted By RedSouljaz
Hi, mau tanya nih aga sedikit tricky:

Misalkan gua punya table kaya gini:

name , date_transaction
-------------------------------------
jojo, 2014-1-1 00:01
jojo, 2014-1-1 00:02
jojo, 2014-1-1 00:03
jame, 2014-1-1 00:04
jame, 2014-1-1 00:05
jame, 2014-1-1 00:06
soso, 2014-1-1 00:07
soso, 2014-1-1 00:08
soso, 2014-1-1 00:09
jojo, 2014-1-1 00:10
jojo, 2014-1-1 00:11
jojo, 2014-1-1 00:12
soso, 2014-1-1 00:13
soso, 2014-1-1 00:14
soso, 2014-1-1 00:15

nah, gua mau hasilnya tuh di group, tapi berdasarkan order dari date_transaction seperti ini hasilnya:

name, start_date, end_date
---------------------------------------------------
jojo, 2014-1-1 00:01, 2014-1-1 00:03
jame, 2014-1-1 00:04, 2014-1-1 00:06
soso, 2014-1-1 00:07, 2014-1-1 00:09
jojo, 2014-1-1 00:10, 2014-1-1 00:12
soso, 2014-1-1 00:13, 2014-1-1 00:15

Kira2 bisa ga ya kalo begini hasilnya?

Master2 SQL pls help

Thanks


select * from namatabel order by date_transaction

sql

bisa gan,

select name, min (date_transaction) start_date, max(date_transaction) end_date from [namatable] group by name order by start_date

mudah2an bener gan
regards,
ini mah bukan digroup tapi di order by date aja
Quote:Original Posted By zweig
bisa gan,

select name, min (date_transaction) start_date, max(date_transaction) end_date from [namatable] group by name order by start_date

mudah2an bener gan
regards,


Ngulik dikit gan (not tested)
Code:
select name, start_date, end_date from (
select name, min (date_transaction) start_date, max(date_transaction) end_date from namatable group by name
) order by start_date