当前位置: 代码迷 >> SQL >> 好手速来帮忙修改一个sql语句,关于left join的
  详细解决方案

好手速来帮忙修改一个sql语句,关于left join的

热度:87   发布时间:2016-05-05 13:37:37.0
高手速来帮忙修改一个sql语句,关于left join的。
left join 跟where 联合起来怎么用?
SQL code
select * from(select b.order_id,a.firstname,a.lastname,a.institution,a.phone,b.service_type from po.account as a,po.order_main as b where a.country='Japan' and a.acc_no=b.acc_no and b.order_id=(select max(b.order_id) from po.order_main as b where b.acc_no=a.acc_no) ) as c left join po.account as d on c.acc_no=d.acc_no group by b.order_id
此中有点错误,希望高手指出来。还有一段是我修改的,但是查询出来的数据并没有改变。
SQL code
select b.order_id,a.firstname,a.lastname,a.institution,a.phone,b.service_type from po.account as a left join po.order_main as b on a.acc_no=b.acc_no where a.country='Japan'   and b.order_id=(select max(b.order_id) from po.order_main as b where b.acc_no=a.acc_no)  group by b.order_id



------解决方案--------------------
select b.order_id,a.firstname,a.lastname,a.institution,a.phone,b.service_type from po.account as a left join 

po.order_main as b on a.acc_no=b.acc_no where a.country='Japan' and b.order_id=(select max(b.order_id) 

from po.order_main as b where b.acc_no=a.acc_no) group by b.order_id

不是标准的SQL语句
select b.order_id from po.account as a left join 

po.order_main as b on a.acc_no=b.acc_no where a.country='Japan' and b.order_id=(select max(b.order_id) 

from po.order_main as b where b.acc_no=a.acc_no) group by b.order_id

------解决方案--------------------
这个问题似乎原来问过,不知道为什么不给出数据以供测试
------解决方案--------------------
group by b.order_id以后选择*号?
  相关解决方案