mysql获取关联表下最新数据
Jun 23, 2016 pm 01:49 PM 目前最新的数据能获取到,但是我想要获取关联表b最新入库时间下的数据,在根据最新入库时间返回关联表a在当前最新入库时间下的数据,没有则返回0
我自己是这样写的
SELECT fang_time, city_name, IF(area is NULL,0,area), IF(taoshu is NULL,0,taoshu) FROM f_city AS fc LEFT JOIN (SELECT * FROM f_chengjiao ORDER by fang_time DESC) AS fcj USING (city_id) GROUP BY fc.city_id
我的2张关联表图
关联表a
关联表b
回复讨论(解决方案)
SELECT fang_time, city_name, IF(AREA IS NULL,0,AREA) AS arra, IF(taoshu IS NULL,0,taoshu) AS taoshu
FROM f_city AS fc INNER JOIN
(SELECT * FROM f_chengjiao ORDER BY fang_time DESC) AS fcj
USING (city_id) ORDER BY fcj.fang_time DESC
你要的是不是这样的,如果不是欢迎追问。
SELECT fang_time, city_name, IF(AREA IS NULL,0,AREA) AS arra, IF(taoshu IS NULL,0,taoshu) AS taoshu
FROM f_city AS fc INNER JOIN
(SELECT * FROM f_chengjiao ORDER BY fang_time DESC) AS fcj
USING (city_id) ORDER BY fcj.fang_time DESC
你要的是不是这样的,如果不是欢迎追问。
你这样写全部的都出来了,并没有分组和没有新纪录的地区显示为0

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP's big data structure processing skills

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times.

How to optimize MySQL query performance in PHP?

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year!

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP?
