Home » SQL & PL/SQL » SQL & PL/SQL » Not a group by expression (but not in sqlplus) (VBA Windows 7)
Not a group by expression (but not in sqlplus) [message #651408] Tue, 17 May 2016 09:16 Go to next message
oteixeira
Messages: 33
Registered: May 2007
Member
Hello to all,

I have this query returning "ORA-00979 not a GROUP BY expression"
The error message does not show which column...
When I run the query in sqlplus it does not produce any error.
Can someone please give me an idea of how to solve this?
Many thanks in advance.
Octavio
Private Sub CommandButton1_Click()
On Error GoTo erro
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ccmd As New ADODB.Command
Dim tourist1 As New ADODB.Parameter 'par 1
Dim data_ini As New ADODB.Parameter 'par 2
Dim data_fin As New ADODB.Parameter 'par 3
Dim iloc As New ADODB.Parameter 'par4
Dim tourist2 As New ADODB.Parameter ' par 5
Dim tourist3 As New ADODB.Parameter 'par 6
Dim dbConnectStr As String
    dbConnectStr = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.172.99.33)(PORT=1561))(CONNECT_DATA=(SERVICE_NAME=PRODL)));User ID=APPS;Password=APPS;"
    conn.ConnectionString = dbConnectStr
    conn.Open
ccmd.ActiveConnection = conn
ccmd.CommandText = "SELECT ilo.name, c.name, decode(?,'Y',t.NAME,'ALL'), f.FLIGHT_NUMBER, to_char(f.flight_date_aux, 'DD-Mon-YYYY'), r.reference ,sum((Case When nvl(t.age,50) > 14 Then '1' Else '0' End)* nvl(t.quantity,1)), sum((Case When nvl(t.age,50) between 2 and 14 Then '1' Else '0' End) * nvl(t.quantity,1)), sum((Case When nvl(t.age,50) < 2 Then '1' Else '0' End) * nvl(t.quantity,1)), sum(nvl(t.quantity,1)) from inc_tourists t, inc_reservations r, inc_flights f, inc_customers_v c, inc_invoicing_locations ilo where t.reservation_id = r.reservation_id and r.arrival_flight_id = f.flight_id and r.customer_id = c.customer_id and r.invoicing_location_id = ilo.invoicing_location_id and f.flight_date_aux between to_date(?, 'DD-MM-YYYY') and to_date(?, 'DD-MM-YYYY') and ILO.NAME = ? group by ilo.name, c.name, f.flight_date_aux, f.FLIGHT_NUMBER, r.reference, decode(?, 'Y', t.NAME, 'ALL') order by ilo.name, c.name, f.flight_date_aux, f.FLIGHT_NUMBER, r.reference, decode(?, 'Y', t.NAME, 'ALL')"
ccmd.CommandText = "SELECT ilo.name" _
& " ,c.name, decode(?, 'Y', t.NAME, 'ALL'), f.FLIGHT_NUMBER , to_char(f.flight_date_aux, 'DD-Mon-YYYY')" _
& " ,r.reference" _
& " ,sum(( Case When nvl(t.age,50) > 14 Then '1'" _
& "Else '0' End" _
& ") * nvl(t.quantity,1))" _
& " ,sum(( Case When nvl(t.age,50) between 2 and 14 Then '1'" _
& " Else '0'  End" _
& " ) * nvl(t.quantity,1))" _
& " ,sum(( Case When nvl(t.age,50) < 2 Then '1'" _
& "Else '0' End" _
& " ) * nvl(t.quantity,1))" _
& " ,      sum(nvl(t.quantity,1))" _
& " from inc_tourists t, inc_reservations r, inc_flights f, inc_customers_v c, inc_invoicing_locations ilo" _
& " where t.reservation_id = r.reservation_id and r.arrival_flight_id = f.flight_id" _
& " and r.customer_id = c.customer_id and r.invoicing_location_id = ilo.invoicing_location_id" _
& " and f.flight_date_aux between to_date(?, 'DD-MM-YYYY') and to_date(?, 'DD-MM-YYYY')" _
& " and ILO.NAME = ? group by ilo.name, c.name, f.flight_date_aux" _
& " ,f.FLIGHT_NUMBER, r.reference, decode(?, 'Y', t.NAME, 'ALL')" _
& " order by ilo.name, c.name, f.flight_date_aux, f.FLIGHT_NUMBER, r.reference, decode(?, 'Y', t.NAME, 'ALL')"
Set tourist1 = ccmd.CreateParameter("one", adVariant, adParamInput, 1, TextBox3.Text)
Set data_ini = ccmd.CreateParameter("two", adVariant, adParamInput, 1, TextBox1.Text)
Set data_fin = ccmd.CreateParameter("three", adVariant, adParamInput, 1, TextBox2.Text)
Set iloc = ccmd.CreateParameter("four", adVariant, adParamInput, 1, ComboBox1.Text)
Set tourist2 = ccmd.CreateParameter("five", adVariant, adParamInput, 1, TextBox3.Text)
Set tourist3 = ccmd.CreateParameter("six", adVariant, adParamInput, 1, TextBox3.Text)
ccmd.Parameters.Append tourist1
ccmd.Parameters.Append data_ini
ccmd.Parameters.Append data_fin
ccmd.Parameters.Append iloc
ccmd.Parameters.Append tourist2
ccmd.Parameters.Append tourist3

Set rst = ccmd.Execute
If Err.Number <> 0 Then
erro:     aux = MsgBox(CStr(Err.Number) & ":" & Err.Description, vbOKOnly, "ERRO - " & Err.Source)  '
End If
conn.Close
End Sub

Re: Not a group by expression (but not in sqlplus) [message #651413 is a reply to message #651408] Tue, 17 May 2016 09:41 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT ilo.name, 
       c.name, 
       Decode(?, 'Y', t.name, 
                 'ALL'), 
       f.flight_number, 
       To_char(f.flight_date_aux, 'DD-Mon-YYYY'), 
       r.reference, 
       SUM(( CASE 
               WHEN Nvl(t.age, 50) > 14 THEN '1' 
               ELSE '0' 
             END ) * Nvl(t.quantity, 1)), 
       SUM(( CASE 
               WHEN Nvl(t.age, 50) BETWEEN 2 AND 14 THEN '1' 
               ELSE '0' 
             END ) * Nvl(t.quantity, 1)), 
       SUM(( CASE 
               WHEN Nvl(t.age, 50) < 2 THEN '1' 
               ELSE '0' 
             END ) * Nvl(t.quantity, 1)), 
       SUM(Nvl(t.quantity, 1)) 
FROM   inc_tourists t, 
       inc_reservations r, 
       inc_flights f, 
       inc_customers_v c, 
       inc_invoicing_locations ilo 
WHERE  t.reservation_id = r.reservation_id 
       AND r.arrival_flight_id = f.flight_id 
       AND r.customer_id = c.customer_id 
       AND r.invoicing_location_id = ilo.invoicing_location_id 
       AND f.flight_date_aux BETWEEN To_date(?, 'DD-MM-YYYY') AND 
                                     To_date(?, 'DD-MM-YYYY') 
       AND ILO.name = ? 
GROUP  BY ilo.name, 
          c.name, 
          f.flight_date_aux, 
          f.flight_number, 
          r.reference, 
          Decode(?, 'Y', t.name, 
                    'ALL') 
ORDER  BY ilo.name, 
          c.name, 
          f.flight_date_aux, 
          f.flight_number, 
          r.reference, 
          Decode(?, 'Y', t.name, 
                    'ALL') 

GROUP BY clause is missing below
To_char(f.flight_date_aux, 'DD-Mon-YYYY'),
Re: Not a group by expression (but not in sqlplus) [message #651415 is a reply to message #651413] Tue, 17 May 2016 09:56 Go to previous messageGo to next message
JNagtzaam
Messages: 36
Registered: July 2015
Location: Alkmaar
Member

That's why we like formatting Wink
Re: Not a group by expression (but not in sqlplus) [message #651424 is a reply to message #651413] Tue, 17 May 2016 10:35 Go to previous messageGo to next message
oteixeira
Messages: 33
Registered: May 2007
Member
Thank a million, you saved my day. But, even missing in SQL, the query run with no error...
Re: Not a group by expression (but not in sqlplus) [message #651427 is a reply to message #651424] Tue, 17 May 2016 12:13 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

There is a bug in some versions that "allows" this.
This is why we like to have the full Oracle version number, with 4 decimals like 11.2.0.4.

Previous Topic: Compare 2 tables and upadte 1
Next Topic: MEMBER OF condition across DB Link
Goto Forum:
  


Current Time: Fri Apr 26 03:24:19 CDT 2024