Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 19:52
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
SQL Left Join
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
beethamd

Joined: 16 Jun 2009
Posts: 21

PostPosted: Mon 27 Sep 2010, 13:57    Post subject:  SQL Left Join  

Say there is a big table - like,

schedules_2weeks
emp_id,code
001,a
002,b
003,b
001,a
004,a
005,b
002,a

and I want to have a count of A for each emp_id. I thought I'd try -

SELECT t1.emp_id, t2.a_count FROM schedules_2weeks AS t1
LEFT JOIN (SELECT emp_id, count(*) a_count WHERE code = "a" group by emp_id) AS t2
ON t1.emp_id=t2.emp_id

This query doesn't run... any ideas?
Back to top
View user's profile Send private message 
beethamd

Joined: 16 Jun 2009
Posts: 21

PostPosted: Tue 28 Sep 2010, 08:54    Post subject:  

Sorted it, should be -

SELECT t1.emp_id, t2.a_count FROM (SELECT DISTINCT emp_id FROM schedules_2weeks) t1 LEFT JOIN (SELECT emp_id, count(*) a_count FROM schedules_2weeks WHERE schedules_2weeks.code = 'a' GROUP BY emp_id) t2 ON t1.emp_id = t2.emp_id ORDER BY `t2`.`a_count` ASC
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6430
Location: Auckland, New Zealand

PostPosted: Wed 29 Sep 2010, 00:53    Post subject:  

In the future you might like to try a forum more directly related to SQL... you'll probably receive more help that way.
_________________
DEATH TO SPREADSHEETS
- - -
Classic Puppy quotes
- - -
Beware the demented serfers!
Back to top
View user's profile Send private message 
beethamd

Joined: 16 Jun 2009
Posts: 21

PostPosted: Sun 10 Oct 2010, 04:17    Post subject:  

This forum is headed, "For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy."

Seems fair enough to ask a question here.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6430
Location: Auckland, New Zealand

PostPosted: Sun 10 Oct 2010, 04:59    Post subject:  

Certainly, but your chances of receiving help might be better elsewhere.
_________________
DEATH TO SPREADSHEETS
- - -
Classic Puppy quotes
- - -
Beware the demented serfers!
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0439s ][ Queries: 11 (0.0068s) ][ GZIP on ]