Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
how to max(count(id))
Old 08-20-2008, 11:20 AM how to max(count(id))
Junior Talker

Posts: 4
Name: hasan
Trades: 0
i have table like this

id tanggal airline h_jual
1 2008-08-03 2 458888
2 2008-08-05 2 500000
3 2008-08-05 1 500000
4 2008-08-05 3 709999
5 2008-05-13 1 500000
6 2008-07-13 3 709999
7 2008-06-13 3 500000
8 2008-01-13 1 458888
9 2008-01-13 1 500000
10 2008-02-13 3 458888
11 2008-03-13 3 458888
12 2008-04-13 2 458888
13 2008-09-14 4 458888
14 2008-09-14 2 1200000
15 2008-09-14 4 1200000
16 2008-01-14 2 709999
17 2008-01-17 1 1200000
18 2008-01-17 2 1200000
19 2008-01-17 3 1200000
20 2008-01-17 4 1200000
21 2008-02-17 1 1200000

i wrote like this
Code:

SELECT distinct year(tanggal) as year, month(tanggal) as month, count(id) as jml_transaksi, airline as airline FROM `table` where year(tanggal)='2008' group by year(tanggal), month(tanggal), airline order by tanggal asc


i got:

year |month |jml_transaksi |airline
2008 1 3 1
2008 1 2 2
2008 1 1 3
2008 1 1 4
2008 2 2 3
2008 2 1 1
2008 2 1 2
2008 2 1 4
2008 3 2 3
2008 3 1 4
2008 3 1 1
2008 3 1 2
2008 4 2 2
2008 4 1 1
2008 4 2 3
2008 4 1 4
2008 5 2 1
2008 5 1 2
2008 5 1 3
2008 5 1 4
2008 6 2 3
2008 6 1 4
2008 6 1 1
2008 6 1 2
2008 7 2 3
2008 7 1 1
2008 7 1 2
2008 7 1 4
2008 8 3 2
2008 8 2 3

i want got max in count(id) out? like in month 1 2008 i got 3 for maximum number even for 1,2,3,4 airline, how to get this result? any idea?
i try this
Code:

SELECT distinct year(tanggal) as year, month(tanggal) as month, count(id) as jml_transaksi, airline as airline, max(count(id)) FROM `keuangan` where year(tanggal)='2008' group by year(tanggal), month(tanggal), airline order by tanggal asc

but error!

Thanks
recosmic is offline
Reply With Quote
View Public Profile Visit recosmic's homepage!
 
 
Register now for full access!
Old 08-20-2008, 11:28 AM Re: how to max(count(id))
SmartBomb's Avatar
Average Talker

Posts: 27
Name: Dave
Trades: 0
I'm not sure but I think you can't use distinct and count with a group by on the right hand side of the statement.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
SmartBomb is offline
Reply With Quote
View Public Profile
 
Old 08-20-2008, 11:45 AM Re: how to max(count(id))
Skilled Talker

Posts: 61
Trades: 0
Wow I think you are over-killing this one.

How about:

SELECT * FROM table ORDER BY date DESC LIMIT 1
__________________

Please login or register to view this content. Registration is FREE

just_a_pod is offline
Reply With Quote
View Public Profile
 
Old 08-20-2008, 11:57 AM Re: how to max(count(id))
Junior Talker

Posts: 4
Name: hasan
Trades: 0
Quote:
Originally Posted by just_a_pod View Post
Wow I think you are over-killing this one.

How about:

SELECT * FROM table ORDER BY date DESC LIMIT 1
yes, i think i'm over-killing for this one. but in here i want extract year and month from date. i want group every airline table have own result.

i think distinct can't use in here to, i just try any possibilities. but i still can get what i want.

i hope my explanation for this problem is clear enough.

anybody can helpme
recosmic is offline
Reply With Quote
View Public Profile Visit recosmic's homepage!
 
Old 08-22-2008, 08:40 PM Re: how to max(count(id))
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Select Max(jml_transaksi) As TheValue From (
SELECT distinct year(tanggal) as year, month(tanggal) as month, count(id) as jml_transaksi, airline as airline FROM `table` where year(tanggal)='2008' group by year(tanggal), month(tanggal), airline order by tanggal asc
) As InnerQueryDefinition
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 09-07-2008, 04:41 PM Re: how to max(count(id))
vanko007a's Avatar
Novice Talker

Posts: 5
Name: Ivan Kolev
Trades: 0
SELECT MAX(field) AS value from(here's your select query) as defineVar;
vanko007a is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to max(count(id))
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24225 seconds with 12 queries