amiwrong123:有一个 java 类;
@Data
@Alias("Customer")
public class Customer {
private String custName;
private String address;
private List<Order> orderList;
}
<select id="getCustomer" resultMap="CustomerAndOrder">
select * from test.orders a, test.customers b where a.cust_id = b.cust_id
</select>
<resultMap id="CustomerAndOrder" type="Customer">
<result property="custName" column="cust_name"/>
<result property="address" column="cust_address"/>
<collection property="orderList" ofType="Order">
<result property="orderNum" column="order_num"/>
<result property="orderDate" column="order_date"/>
</collection>
</resultMap>
getCustomer 方法是为了查询每个顾客,都有哪些订单。
执行 getCustomer 方法后,可以看到这个链表查询起到了类似 group by 的作用,以 cust_name 和 cust_address 分组,将每个组内的订单信息弄进了一个集合内。类似于:
select
cust_name,
cust_address,
(select 组内各行的 order_num,order_date into a List)
from test.orders a, test.customers b where a.cust_id = b.cust_id
group by cust_name, cust_address
大概是上面这个意思,但实际上 mysql 无法做到这种语句。
然后我想问的是:
- 假设(select 组内各行的 order_num,order_date into a List)这种行为支持的话,上面这种查询是否等价于上面这 sql 语句?
- 如果等价,出现在<result property="xxx" column="yyy"/>的 yyy 一定是 group by 的条件呗?
另外,mybatis 官方文档的这个例子:
<!-- 非常复杂的结果映射 -->
<resultMap id="detailedBlogResultMap" type="Blog">
<constructor>
<idArg column="blog_id" javaType="int"/>
</constructor>
<result property="title" column="blog_title"/>
<association property="author" javaType="Author">
<id property="id" column="author_id"/>
<result property="username" column="author_username"/>
<result property="password" column="author_password"/>
<result property="email" column="author_email"/>
<result property="bio" column="author_bio"/>
<result property="favouriteSection" column="author_favourite_section"/>
</association>
<collection property="posts" ofType="Post">
<id property="id" column="post_id"/>
<result property="subject" column="post_subject"/>
<association property="author" javaType="Author"/>
<collection property="comments" ofType="Comment">
<id property="id" column="comment_id"/>
</collection>
<collection property="tags" ofType="Tag" >
<id property="id" column="tag_id"/>
</collection>
<discriminator javaType="int" column="draft">
<case value="1" resultType="DraftPost"/>
</discriminator>
</collection>
</resultMap>
是否可以认为其等价 sql 语句是 group by blog_title, author_id, author_username, author_password, author_email, author_bio, author_favourite_section?
mysql 获取某商品的前十条评论,不使用 group by 有什么好的方案吗?wmwmajie:mysql 获取某商品的前十条评论,不使用 group by 有什么好的方案吗? 发现 gourp by 需要先分组在过滤出前 10 个,所有要处理的数据反而会很多。 有什么方式不用 group by 简洁高效吗?求指教xmumiffy:指定商品的评论,那不是 order 加 limit 就可以么,具体表结构是什么? daozhihun:只…
SQL:GROUP BY记录,然后从每个组获取最后一条记录? - phpThis question already has answers here: Closed 7 years ago. Possible Duplicate: SQL Server: Only last entry in GROUP BY我有一张这样的桌子:id| name | attendence 1 | Naveed| 1 2 | Naveed| 1 3…
关应 AirpodsPRO 的 音频空间xiaocongcong:不管是官方还是网友好像都没有说清楚这个空间功能 但是由此我联想到第五人格这个游戏 这款游戏里面所有声音都与游戏角色所处空间的位置是有联系的。 比如说队友在游戏里开了一枪,但他不在你的屏幕视野范围内,但是只要你戴了耳机能很清楚的知道是声音所处的方向和远近。 再比如舞女放置了一个音乐盒,你可以听到从远到近的距离感, 但是!重点来了,只要…
ios 上有没有好用的音乐播放器支持 dlna 的razios:想播放群晖上音乐,但是 ds music 感觉不好用xtx:可以直接放在网易云音乐云盘或者 qq 音乐微云云盘上听,网易云有 2t,用来听歌足够了。
iOS14 的 Safari 浏览器怎么打开网页翻译?cxxxxx:更新到 iOS14 后用 Safari 浏览器打开英文网页找不到网页翻译功能,我看其他人的浏览器是有这个功能的,是不是还有什么开关要设置的吗?shanwu:地区改到美国或加拿大。