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 Sat 25 Oct 2014, 04:53
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 Posts_count  
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: 6449
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: 6449
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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