mysql order排序时能否用其它表中的数据来排序?
情况是这样的
A表字段user dt dg
a 15 10
b 17 15
B表字段user title jh
a xxx 1
b xxx 0
b xxxxx 0
a xxxxx 0
b xxxxx 1
想要实现的是,根据A表中的user与B表中的user值得出 B表中的有多少与该user相关的数据,按数据条数从多到少排序,然后输出结果为
user dt jh B表中的条数
b 17 1 3
a 15 1 2
------解决方案--------------------
select A.*, T.jh from A, (select user,count(*) as jh from B) T where A.user=T.user order by T.jh desc
------解决方案--------------------
select a.user,a.dt,sum(b.jh) as jh,count(b.user) as counter from a inner join b on a.user=b.user group by b.user order by counter desc;
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号