可能重复:
每个派生表都必须有自己的别名
我有两个具有相同列的 MYSQL 表我正在尝试获取 sum qtd,其中 produto 相同但我有错误“每个派生表必须有自己的别名”请帮助
MySqlCommand cmd = cnn.CreateCommand();
StringBuilder query = new StringBuilder();
query.Append("select produto,sum(qtd) from ( ");
query.AppendFormat(" select x.produto,x.qtd from itens_venda x where x.data='{0:MM/dd/yyyy}'", new object[] { data1 });
query.Append(" Union all ");
query.AppendFormat(" select y.produto,y.qtd from itens_venda_fiscal y where y.data='{0:MM/dd/yyyy}'", new object[] { data1 });
query.Append(" ) group by produto order by sum(qtd) desc ");
cmd.CommandText = query.ToString();
MySqlDataReader reader = cmd.ExecuteReader();
while ( reader.Read() )
{
Codigo.Add(reader.GetString(0));
Quantidade.Add(reader.GetString(1));
}