If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with tricky SELECT

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-15-04, 12:16
bash bash is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
Help with tricky SELECT

I have a table with three cols:
Firm No, Date, and Ret.

Code:
Firm No 	Date    	Ret
1		20040101	.01
1		20040102	-.01
1		20040103	.01
1		20040104	.02
2		20040102	.01
2		20040103	-.01
3		20040101	-.02
3		20040102	.05
3		20040103	-.06
3		20040104	.07
4		20040101	-.08
4		20040102	.12
4		20040103	.02

I'd like to select all for the returns for the firms which have observations for each day.

There are a number of ways to get the numbr of days. My fav so far is

SELECT COUNT(DISTINCT date) from myTable;

Which will return the number of days.

So far I have't found a way to get it to let me reutns the firmno, date and rets for those which have all obs

(In this example the return woudl ideally be)
Code:
Firm No 	Date    	Ret
1		20040101	.01
1		20040102	-.01
1		20040103	.01
1		20040104	.02
3		20040101	-.02
3		20040102	.05
3		20040103	-.06
3		20040104	.07
I've tried code like

Code:
SELECT firmno,date,ret,COUNT(*) as numObs
FROM myTable
GROUP BY firmno
HAVING numObs=MAX(numObs)
with no luck (Syntax error).

Any help would be greatly appreciated. Oh, and SQL is MySQL 4.0.18.

Thanks,
Kevin
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On