询问 [英] query

查看:64
本文介绍了询问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i在我尝试使用公共值从两个表中检索值时遇到问题。

ie

table1有emp_id和name,table2有emp_id和prod ..

i试图使用查询

选择名称,从table1 prod,table2 where table1.emp_id =''some value'' ;

问题是表2中存在数据冗余并使用不同的关键字我也得到了不需要的值。

ie。

select distinct name,prod from table1,table2 where table1.emp_id =''some value'';

i得到了prod的所有值。

我应该使用什么样的查询表中的反向值以避免冗余和不需要的数据。

解决方案

试试这个:

展开 | 选择 | 换行 | 行号


< blockquote>为了避免JOIN中数据的冗余,你需要通过表名来限定字段名称。


感谢查询它的工作正常。

i面对当我试图知道特定emp_id销售的产品数量时出现问题



从t1,t2组t2.id选择t1.name,count(prod) ;


错误不是GROUP BY表达式。


hi,
i faced a problem when i tried to retrive value from two table using a common value.
ie
table1 has emp_id and name,table2 has emp_id and prod..
i tried to use the query
select name,prod from table1,table2 where table1.emp_id=''some value'';
The problem was there was redundancy of data in table2 and using distinct key word also i got unwanted values.
ie.
select distinct name,prod from table1,table2 where table1.emp_id=''some value'';
i got all the values of prod.
what kind of query i should use to retrive value from both the table to avoid redundant and unwanted data.

解决方案

Try this:

Expand|Select|Wrap|Line Numbers


To avoid redundancy of data in JOIN, you need to qualify the field names by the table name.


Thanks for the query its work fine.
i faced a problem when i tried to know the number of products sold by a particular emp_id
ie
select t1.name,count(prod) from t1,t2 group t2.id;

The error was not a GROUP BY expression.


这篇关于询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆