Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get count plus detail in single SQL?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00663662
Message ID:
00663791
Vues:
7
This message has been marked as the solution to the initial question of the thread.
Try
SELECT Questions.*, COUNT(UserCode) AS VoteCount, ;
          SUM( IIF(UserCode = lcUserCode, 1, 0)) AS VoteCountCurentUser ;
	FROM Questions ;
	LEFT JOIN Votes ;
	WHERE Questions.SurveyPK=Votes.SurveyPK ;
	ORDER BY CloseDate DESC ;
	GROUP BY SurveyPK ;
	INTO CURSOR TQuery
>I'm doing a survey module and want to run a single query that gives me the total number of votes in a survey (easy with COUNT and GROUP BY), PLUS whether the logged in user voted in each one or not.
>
>One table is Questions, the second is Votes. Here's what I have - it gives the vote count for each question, but not whether the current user (lcUserCode) voted in each one:
>
>
SELECT Questions.*, UserCode, COUNT(UserCode) AS VoteCount ;
>	FROM Questions ;
>	LEFT JOIN Votes ;
>	WHERE Questions.SurveyPK=Votes.SurveyPK ;
>	ORDER BY CloseDate DESC ;
>	GROUP BY SurveyPK ;
>	INTO CURSOR TQuery
>
>SurveyPK is the PK in the Questions table. Of course, I'm interested in listing all questions.
>
>Any ideas?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform