|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Error with Groupby
i'm having an error with my code, it says the column I use for my sub query has to be in the group by as well, so when i put the history_id in the group by, the resulting file wont have 1 instance of the name as indicated by my distinct, but multiple ones when i really just want one, please help, thanks
Code:
sqlText2 = "SELECT Distinct" & _ " name AS Thename, " & _ " Count(age) AS Rolled_age, " & _ " SUM(per_dol) AS Rolled_dol, " & _ " (SELECT SUM(grs_sub) from history_old where history_old.history_id=history_rep_old.history_id and quick_sort = 1) as number_one, "&_ " (SELECT SUM(grs_sub) from history_old where history_old.history_id=history_rep_old.history_id and quick_sort = 0) as number_zero, "&_ " FROM history_rep_old " & _ " WHERE " & where_clause &_ "GROUP BY name, history_id;" |
|
#2
|
|||
|
|||
|
This can happen when you use aggregate functions and you want to include a field that you don't want to group on. Have to do something with that field (such as Last or Max or Count). Query as posted difficult to read so I have repeated it here without edits other than the line continuations.
Code:
sqlText2 = "SELECT Distinct " & _ "name AS Thename, " & _ "Count(age) AS Rolled_age, " & _ "SUM(per_dol) AS Rolled_dol, " & _ "(SELECT SUM(grs_sub) from history_old " & _ "Where history_old.history_id=history_rep_old.history_id " & _ "And quick_sort = 1) as number_one, " & _ "(SELECT SUM(grs_sub) from history_old " & _ "Where history_old.history_id=history_rep_old.history_id " & _ "And quick_sort = 0) as number_zero, " & _ "FROM history_rep_old " & _ "WHERE " & where_clause " & _ "GROUP BY name, history_id;" Last edited by June7 : October 21st, 2009 at 05:57 PM. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SQL Error with Groupby |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|