Oracle:错误ORA-00937:不是Oracle Join Query中的单组组功能

时间:2015-06-05 10:17:55

标签: sql oracle

给出两个表格,城市和国家,其描述如下。打印所有大洲的名称(关键字:Country.Continent)以及向下舍入到最接近的整数的平均城市人口。

PS#1:City.CountryCode和Country.Code是同一个键。 PS#2:没有城市的国家不应该被列入产出。

City

 Field           Type     

 ID               int(11)  
 Name            char(35)    
 CountryCode      char(3)  
 District         char(20) 
 Population        int(11) 

Country    

Field        Type      

 Code           char(3)     
 Name          char(52)    
 Continent      char(50)  
 Region          char(26)   
 SurfaceArea     float(10,2)
 IndepYear      smallint(6) 
 Population      int(11)     
 LifeExpectancy  float(3,1)  
 GNP             float(10,2) 
 GNPOld          float(10,2) 
 LocalName      char(45)   
 GovernmentForm char(45)    
 HeadOfState     char(60)   
 Capital         int(11)    
 Code2           char(2)    

我尝试通过Cy.Continent从Country Cy加入City C on(C.CountryCode = Cy.Code)组中选择avg(C.Population);

并且

选择avg(C.Population),Cy.Continent从Country Cy加入City C on(C.CountryCode = Cy.Code);

但它给了我一个错误

  

第1行的错误:ORA-00937:不是单组组功能

2 个答案:

答案 0 :(得分:0)

我想你必须在Cy.continent分组的第一次尝试的select语句中添加cy.continent。

尝试这样的事情(地板用于"将其向下舍入到最接近的整数" - 部分):

SELECT floor(AVG(City.population)),Country.continent FROM City JOIN Country ON City.CountryCode = Country.Code
GROUP BY Country.continent;

答案 1 :(得分:-1)

protected void btn_Registration_Click(object sender, EventArgs e)
{
    try
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
        conn.Open();
        string insertQuery = "insert into UserData(Username,Firstname,Lastname,Email,Password,CustomerType,DeliveryAddress,Zip,ContactNumber)values(@Username,@Firstname,@Lastname,@Email,@Password,@CustomerType,@DeliveryAddress,@Zip,@ContactNumber)";
        SqlCommand scm = new SqlCommand(insertQuery, conn);
        scm.Parameters.AddWithValue("@Username", txtUser.Text);
        scm.Parameters.AddWithValue("@Firstname", txtFN.Text);
        scm.Parameters.AddWithValue("@Lastname", txtLN.Text);
        scm.Parameters.AddWithValue("@Email", txtEmail.Text);
        scm.Parameters.AddWithValue("@Password", BusinessLayer.ShoppingCart.CreateSHAHash(txtPW.Text));
        scm.Parameters.AddWithValue("@CustomerType", RadioButtonList1.SelectedItem.ToString());
        scm.Parameters.AddWithValue("@DeliveryAddress", txtAddress.Text);
        scm.Parameters.AddWithValue("@Zip", txtZip.Text);
        scm.Parameters.AddWithValue("@ContactNumber", txtContact.Text);

        scm.ExecuteNonQuery();
        txtUser.Text = "";
        txtFN.Text = "";
        txtLN.Text = "";
        txtEmail.Text = "";
        txtAddress.Text = "";
        txtZip.Text = "";
        txtContact.Text = "";
        label_register_success.Text = ("Registration Successful!");
        conn.Close();
     }
     catch (Exception ex)
     {
        Response.Write("Error:" + ex.ToString());
     }
 }