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以后选择*号?