SQL简单问题

来源:百度知道 编辑:UC知道 时间:2024/09/24 04:26:05
select distinct oea01 订单号码 ,oeb03 项次,oeb04 ?品编号 ,oeb15 交货日期 ,oga02 出货日期
from oea_file,oeb_file,oga_file
where oga16=oea01
and oea01=oeb01
and oeaconf='Y'
and oeb15<today
and oeb15>'20070430'
and oeb12-oeb24+oeb25=0
and oga02<=oeb15
order by oea01;

我用上述命令,查出来的还是每一张单都重复出现两次.如果我想对两个字段加distinct 应该怎么写?

select distinct oea01 订单号码 ,oeb03 项次,distinct oeb04 产品编号 ,oeb15 交货日期 ,oga02 出货日期
这样写对吗?

还有select count(distinct oea01 订单号码) ,oeb03 项次,oeb04 ?品编号 ,oeb15 交货日期 ,oga02 出货日期
这条语句有错吗?

1,from条件最好用join连接
2,oea01 订单号码 应该是oea01 as 订单号码
其他的也是这样
3,select count( oea01)as 订单号码 ,oeb03 as 项次,oeb04 as ?品编号 ,oeb15 as 交货日期 ,oga02 as 出货日期

我用上述命令,查出来的还是每一张单都重复出现两次.是因为你显示的字段--oeb03 项次,oeb04 ?品编号 ,oeb15 交货日期 ,oga02 出货日期 有不一样的数据,就是distinct oea01 订单号码 一样,但其它字段不一样,你将不一样数据列在查询中去掉,再查询就不会有重复了.