We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,599 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

stuck in query..

hey guys this is the structure of the Db:

`Ex_ID` int(11) NOT NULL auto_increment,
`N_Etudiant` varchar(25) NOT NULL,
`Professeur` varchar(50) NOT NULL,
`Foyer` varchar(50) NOT NULL,
`Motif` varchar(50) NOT NULL,
`Date` date NOT NULL,
`Notes` text NOT NULL,
`Autre` varchar(150) NOT NULL,

so basically N_Etudiant is a student name..

so when we insert it looks like

`N_Etudiant` Mike
`Professeur` mrpopins
`Foyer` 301
`Motif` fight
`Date` 2011/01/01
`Notes` none
`Autre` 0

so the query i need is to flag if (N_Etudiant) has the same (Professeur) more the 2 times

cause we need to know if the student (N_Etudiant) has been expelled from class by the same teacher (Professeur) more then 2 times..

is this clear?lol

3
Contributors
3
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
4
Views
techker
Newbie Poster
6 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Off the top of my head I would start with this...

SELECT `Foyer`,
SUM(IF(`Professeur` = "mrpopins", 1,0)) AS `count`
FROM student_table
WHERE `N_Etudiant` = 'Mike'
GROUP BY `N_Etudiant`
ORDER BY count DESC

ppetree
Junior Poster
158 posts since Oct 2009
Reputation Points: 12
Solved Threads: 8
Skill Endorsements: 0
SELECT N_Etudiant, Professeur, count(Professeur) as CP
FROM Foyer
GROUP BY N_Etudiant, Professeur
HAVING CP > 2;
smantscheff
Nearly a Posting Virtuoso
1,297 posts since Oct 2010
Reputation Points: 321
Solved Threads: 270
Skill Endorsements: 8

this is what i came up with

$query = "SELECT N_Etudiant, Professeur
FROM Expulsion
GROUP BY N_Etudiant, Professeur
HAVING COUNT( * ) >=2
LIMIT 0 , 30";
techker
Newbie Poster
6 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0636 seconds using 2.66MB