Click here to Skip to main content
15,895,809 members
Home / Discussions / Database
   

Database

 
AnswerRe: Oracle Error Pin
Member 1043154927-Mar-14 0:28
Member 1043154927-Mar-14 0:28 
QuestionComplex Query Pin
#realJSOP24-Mar-14 4:18
mve#realJSOP24-Mar-14 4:18 
AnswerRe: Complex Query Pin
Simon_Whale24-Mar-14 4:46
Simon_Whale24-Mar-14 4:46 
GeneralRe: Complex Query Pin
#realJSOP24-Mar-14 5:53
mve#realJSOP24-Mar-14 5:53 
QuestionGrouping Results by ElectionName Pin
samflex19-Mar-14 10:44
samflex19-Mar-14 10:44 
AnswerRe: Grouping Results by ElectionName Pin
Jörgen Andersson19-Mar-14 11:02
professionalJörgen Andersson19-Mar-14 11:02 
AnswerRe: Grouping Results by ElectionName Pin
Mycroft Holmes19-Mar-14 12:52
professionalMycroft Holmes19-Mar-14 12:52 
GeneralRe: Grouping Results by ElectionName Pin
samflex19-Mar-14 13:12
samflex19-Mar-14 13:12 
I was not needing for app. The code below is what I used for my app.

It is doing the grouping by electionName but I can't figure out how to count the total count for each candidate.

Can you guys add that bit?

I just to get the total scores for each candidateName

SQL
WITH
ctePreAgg AS
(
 SELECT (ElectionName + ' - ' + CAST(ClosingDate AS VARCHAR(12))) electionName, CASE WHEN Position='Member' THEN '' ELSE Position END As Position, CASE WHEN c.CurrentOfficeHolder='Incumbent' THEN CandidateName + '('+ c.CurrentOfficeHolder + ')' ELSE CandidateName END As CandidateName , c.PositionId,COUNT(*) TotalVotes 
   FROM Candidates c 
   JOIN Positions p ON c.PositionId = p.PositionId
   JOIN Elections e on c.ElectionId = e.ElectionId
  WHERE c.ElectionId IN (1,2,3)
  GROUP BY Position, CandidateId, CandidateName,c.PositionId,CurrentOfficeHolder,AnswerType,ElectionName, ClosingDate
)

  SELECT [OrgName] = CASE WHEN GROUPING(mh.PositionId) = 0 THEN MAX(mh.Position)  ELSE mh.ElectionName END
        ,Names = CASE WHEN GROUPING(mh.PositionId) = 0 THEN MAX(mh.CandidateName)    ELSE '' END
        ,PositionId    = CASE WHEN GROUPING(mh.PositionId) = 0 THEN mh.PositionId   ELSE '' END
        ,TotalCount = CASE WHEN GROUPING(mh.PositionId) = 0 THEN COUNT(*) ELSE '' END
  FROM  ctePreAgg mh
  GROUP BY ElectionName,PositionId WITH ROLLUP
  HAVING GROUPING(mh.ElectionName) = 0
  ORDER BY mh.ElectionName, GROUPING(mh.PositionId) DESC, mh.PositionID;

GeneralRe: Grouping Results by ElectionName Pin
Mycroft Holmes19-Mar-14 14:05
professionalMycroft Holmes19-Mar-14 14:05 
GeneralRe: Grouping Results by ElectionName Pin
samflex19-Mar-14 14:13
samflex19-Mar-14 14:13 
GeneralSSIS - Truncation may occur due to inserting data Pin
Smith201418-Mar-14 2:59
Smith201418-Mar-14 2:59 
AnswerRe: SSIS - Truncation may occur due to inserting data Pin
Kornfeld Eliyahu Peter18-Mar-14 3:00
professionalKornfeld Eliyahu Peter18-Mar-14 3:00 
GeneralRe: SSIS - Truncation may occur due to inserting data Pin
Smith201418-Mar-14 3:07
Smith201418-Mar-14 3:07 
AnswerRe: SSIS - Truncation may occur due to inserting data Pin
Kornfeld Eliyahu Peter18-Mar-14 3:11
professionalKornfeld Eliyahu Peter18-Mar-14 3:11 
GeneralRe: SSIS - Truncation may occur due to inserting data Pin
jschell18-Mar-14 8:44
jschell18-Mar-14 8:44 
GeneralRe: SSIS - Truncation may occur due to inserting data Pin
Mycroft Holmes18-Mar-14 12:55
professionalMycroft Holmes18-Mar-14 12:55 
QuestionSSIS - Truncation may occur due to inserting data Pin
Smith201418-Mar-14 2:54
Smith201418-Mar-14 2:54 
QuestionInserting a new record into 2 tables at the same time Pin
jkirkerx17-Mar-14 11:49
professionaljkirkerx17-Mar-14 11:49 
AnswerRe: Inserting a new record into 2 tables at the same time Pin
Mycroft Holmes17-Mar-14 19:48
professionalMycroft Holmes17-Mar-14 19:48 
GeneralRe: Inserting a new record into 2 tables at the same time Pin
jkirkerx19-Mar-14 13:21
professionaljkirkerx19-Mar-14 13:21 
GeneralRe: Inserting a new record into 2 tables at the same time Pin
Mycroft Holmes19-Mar-14 14:10
professionalMycroft Holmes19-Mar-14 14:10 
GeneralRe: Inserting a new record into 2 tables at the same time Pin
jkirkerx19-Mar-14 16:26
professionaljkirkerx19-Mar-14 16:26 
QuestionStructure Database Pin
sbangani15-Mar-14 5:29
sbangani15-Mar-14 5:29 
AnswerRe: Structure Database Pin
Richard Andrew x6415-Mar-14 10:55
professionalRichard Andrew x6415-Mar-14 10:55 
GeneralRe: Structure Database Pin
sbangani16-Mar-14 12:05
sbangani16-Mar-14 12:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.