作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想合并两个表。输出应该是表A、表B的数据。
SELECT date as Date, COUNT(*) as Transaction, SUM(status=0) as Success
FROM transfer_tx_201503 WHERE time >='00:00:00' AND time <= '$searchterm'
UNION SELECT date as Date, COUNT(*) as Transaction, SUM(status=0) as Success FROM request_tx_201503 WHERE time >='00:00:00' AND time <= '$searchterm' GROUP BY date desc"
我想这样输出:|2015-03-23 | 5 | 3 | 4 | 1 |
表 transfer_tx_2015 中的 5 和 3,表 request_tx_2015 中的 4 和 1
谢谢
最佳答案
可以使用table_a, table_b语法:
SELECT columns FROM table_a, table_b WHERE table_a.id = table_b.id
或者你可以使用连接:
SELECT columns FROM table_a JOIN table_b ON table_a.id = table_b.id
您可以在以下位置阅读有关 JOIN 的更多信息:
关于php - 如何在 SQL (MySQL) 中合并两个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29270494/
我是一名优秀的程序员,十分优秀!