表 a id
1
2
表 baid content
1 asss
1 sf
2 示范法
2 不被
联查后得到
id content
1 asss
null sf
2 示范法
null 不被
就是id相同的给值空
1
2
表 baid content
1 asss
1 sf
2 示范法
2 不被
联查后得到
id content
1 asss
null sf
2 示范法
null 不被
就是id相同的给值空
解决方案 »
- mysql_ping()调用
- 为什么hibernate中hmb.xml中映射了type="text"最后变成了longtext
- 产品分类无限级查询如何查
- 100分求助master-master的重复数据问题
- mysql存储过程 数组
- Mysql:这个sql语句有问题吗??为什么执行不成功呢???
- #1146 - Table 'servicedesk.aaaaccadminprofile' doesn't exist 这是什么原因?
- 一个1G多的sql文件用什么编辑软件可以打得开?
- 两级级菜单一次性查询出来的问题
- sql统计查询,关于树结构,求解!!!
- 之前的问题未解决,但不知如何加分
- 有没有更简便的方法求2个日期之间的相差的小时数
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)mysql> select * from b;
+------+---------+
| aid | content |
+------+---------+
| 1 | asss |
| 1 | sf |
| 2 | 示范法 |
| 2 | 不被 |
+------+---------+
4 rows in set (0.00 sec)mysql> select
-> case when
-> (select count(*) from b where aid=t.aid and content<t.content)=0 -> then a.id end as id,
-> t.content
-> from a inner join b t on a.id=t.aid;
+------+---------+
| id | content |
+------+---------+
| 1 | asss |
| NULL | sf |
| 2 | 示范法 |
| NULL | 不被 |
+------+---------+
4 rows in set (0.00 sec)mysql>
SELECT iif(ma is not null,null,a.aid),a.content from tt4 a left join (select aid,max(id) as ma from tt4 group by aid) b
on a.aid=b.aid and a.id=b.ma