有这样的数据库
表1 country
id cname
1 中国
2 美国
3 加拿大
表2 city
id name cid sj
1 北京 1 2008-07-31 00:00:00
2 上海 1 2008-08-01 00:00:00
3 纽约 2 2008-07-15 00:00:00
4 旧金山 2 2008-07-01 00:00:00
5 温哥华 3 2008-08-01 00:00:00select country.cname as cname ,city.name as cs from country,city where country.id=city.cid group by country.cname having max(UNIX_TIMESTAMP(sj))
显示的结果是:
中国 北京
加拿大 温哥华
美国 纽约 我现在想要的结果是:让时间最新的显示
中国 上海
美国 纽约
加拿大 温哥华
表1 country
id cname
1 中国
2 美国
3 加拿大
表2 city
id name cid sj
1 北京 1 2008-07-31 00:00:00
2 上海 1 2008-08-01 00:00:00
3 纽约 2 2008-07-15 00:00:00
4 旧金山 2 2008-07-01 00:00:00
5 温哥华 3 2008-08-01 00:00:00select country.cname as cname ,city.name as cs from country,city where country.id=city.cid group by country.cname having max(UNIX_TIMESTAMP(sj))
显示的结果是:
中国 北京
加拿大 温哥华
美国 纽约 我现在想要的结果是:让时间最新的显示
中国 上海
美国 纽约
加拿大 温哥华
解决方案 »
- 关于连接
- 求sql语句,包含对特殊字段的sum求和查询
- mysql如何求不连续列中每一列的最大值?
- 重发: MySQL建库的问题,选什么引擎好
- 问个得到查询结果的函数或命令
- 请问 什么软件可以在Windows下控制Linux下的postgreSQL?
- 求救Can't connect to local MySQL server through socket '/tmp/mysql.sock'
- 请教大大,length 和 char_lenght我返回的都是字节长
- mysql 触发器 binlog
- python服务器代码和android studio代码可以无修改跨平台运行吗?
- 求一条SQL语句,高手帮帮忙!!
- sql语句菜鸟问题
where a.id=b.cid and b.sj in (select max(sj) from city where cid=b.cid)