|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Query Question - MYSQL
My Query
SELECT COUNT(DISTINCT TBVIEWER_TRACK.VIEWER_ID) AS COUNT, TITLE FROM TBVIEWER_TRACK INNER JOIN TBPRESENTATIONS USING(PRESENTATION_ID) WHERE TBPRESENTATIONS.PRESENTER_ID='2' AND COUNT < 5 GROUP BY TITLE; My Error: Uknown column 'COUNT' in 'where clause' Any ideas?? |
|
#2
|
||||
|
||||
|
RE: Query Question - MYSQL
It's probably getting confused between the column you named COUNT and the COUNT function. Try changeing the column alias to something else, like CNT.
|
|
#3
|
|||
|
|||
|
RE: Query Question - MYSQL
hey thanx for the response, i tried that to no avail. i got the same error message.
perhaps i am approaching the query wrong as i am not very experienced in MYSQL yet. the tables are organized as such. table names will be all capitals and the fields will be lower case. TBPRESENTATIONS presentation_id presenter_id title start TBVIEWER_TRACK viewer_id TBPRESENTERS presenter_id number_licenses How it all works is each presenter is given a number of licenses (number_licenses). The licenses determine how many viewers can watch the presentation which can be found by counting the unique viewer ids( count(distinct viewer_id) ). What I am trying to extract is the number of viewers exceeding the number of specified licenses per presenter. I also need the date of the presentation(start) and the name (title). Thanx to anyone that attempts to help me out! |
|
#4
|
||||
|
||||
|
RE: Query Question - MYSQL
How do you tie a viewer to a presenter or a presentation?
|
|
#5
|
|||
|
|||
|
RE: Query Question - MYSQL
im sorry, i left out a field
TBPRESENTATIONS presentation_id presenter_id title start TBVIEWER_TRACK presentation_id viewer_id TBPRESENTERS presenter_id number_licenses so... -TBVIEWER_TRACK has the 'presentation_id'. 'presentation_id' is a common field and can be used in a join between TBVIEWER_TRACK and TBPRESENTATIONS if necessary -TBPRESENTATIONS and TBPRESENTERS have a common field in 'presenter_id' sorry for the confusion. |
|
#6
|
||||
|
||||
|
RE: Query Question - MYSQL
I should have looked at your original post more closely. The problem is that you are putting a condition on the count column in the where clause and not in the group by's having clause. Something like this should work:
Code:
SELECT TBPRESENTATIONS.title AS Title, COUNT(DISTINCT TBVIEWER_TRACK.viewer_id) AS Cnt, FROM TBVIEWER_TRACK INNER JOIN TBPRESENTATIONS USING(presentation_id) LEFT JOIN TBPRESENTERS USING(presenter_id) GROUP BY TBPRESENTATIONS.presentation_id HAVING Cnt > TBPRESENTERS.number_licenses; |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Query Question - MYSQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|