想象一下,我有一堆产品,每个产品都有一个评论部分,如果有人留下了很好的评论,他们的评论会得到一个赞,以告知其他用户发现它有帮助。
我有一个名为 CustomerReview 的表,还有一个名为 likeReview 的表,在这个表 (likeReview) 内我有一列:
isLike(值为真、假或空)
我需要让这张表将最有用的评论排在列表顶部。
我该怎么做呢?
我的 SQL 试图让isLike这样做时出错,因为有些评论 (CustomerReview) 与likeReview表无关。
SELECT {c.pk}
FROM{ CustomerReview as c LEFT JOIN LikeReview as l ON {c.pk} = {l.pk} }
WHERE {c.product}=?product
AND {c.LANGUAGE}=?language
ORDER BY {l.ISLIKE } ;
我的 items.xml
<relation code="Review2User" localized="false"
generate="true" autocreate="true">
<sourceElement qualifier="likeReview" type="LikeReview"
cardinality="many" >
</sourceElement>
<targetElement qualifier="customerReview" type="CustomerReview"
cardinality="one">
</targetElement>
</relation>
关系
<typegroup name="LikeReview">
<itemtype code="LikeReview" autocreate="true" generate="true">
<deployment table="likeReview" typecode="15088"/>
<attributes>
<attribute type="Customer" qualifier="customer" >
<modifiers optional="false" unique="true"/>
<persistence type="property"/>
</attribute>
<attribute type="CustomerReview" qualifier="review" >
<modifiers optional="false" unique="true"/>
<persistence type="property"/>
</attribute>
<attribute qualifier="isLike" type="java.lang.Boolean">
<defaultvalue>Boolean.FALSE</defaultvalue>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
</typegroup>