欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

mysql联合查询有关问题

程序员文章站 2024-02-07 18:59:10
...
mysql联合查询问题
Persons" 表:
Id_P LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter homas Changan Street Beijing


"Orders" 表:
Id_O OrderNo Id_P
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 65


怎么查询Persons表id=1 对应Orders的数量

就是
Id_P(1) Adams 2
Id_P(2) Bush 0
Id_P(3) Carter 2
------解决思路----------------------
select Id_P(1) ,LastName from Persons,Orders where Id_O=Id_P;
------解决思路----------------------
select p.Id_P ,p.LastName,(select count(*) from Orders where Id_P=p.Id_P) as counter from Persons p
------解决思路----------------------
select count(Id_P) as shuliang from Orders where Orders.Id_P in (select Id_P from Persons) group by Id_P;
mysql联合查询有关问题

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频