关联2个表的字段,以及别名的用法

普通的查询表语句:select * from t_dangangd_info  t    后面的 表示给表加个别名
编辑数据:select t.*,  t.rowid from t_dangangd_info   t  加了 t,表示专门指这个表。然后通过  t.rowid 这个字段,可以去编辑这个表。
2个表的组合:select b.ywh,b.zmqlhsx,b.qlr ,concat(b.year,b.bdcqh) as zmh,t.jzh, t.rowid from t_dangangd_info t inner join t_zhengmi b on b.ywh=t.ywh where b.zmqlhsx='抵押权'    t 表示 t_dangangd_info这个表;b表示 t_zhengmi这个表 。[表] inner join  [表]...on...[关联条件] 这是俩张表关联的固定语法
 

sql之left join、right join、inner join的区别

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例代码,使用JavaLookupOperation联查询,按2别名排序,使用2字段作为条件: ``` MongoOperations mongoOps = ...; // 通过Spring Data MongoDB获取MongoOperations对象 // 定义lookup操作 LookupOperation lookupOperation = LookupOperation.newLookup() .from("table2") .localField("table1Field") // 1关联字段 .foreignField("table2Field") // 2关联字段 .as("table2Alias"); // 2别名 // 定义sort操作,按2别名排序 SortOperation sortOperation = Aggregation.sort(Sort.Direction.ASC, "table2Alias.fieldToSort"); // 定义match操作,使用2字段作为条件 Criteria matchCriteria = Criteria.where("table2Alias.fieldToMatch").is("matchValue"); MatchOperation matchOperation = Aggregation.match(matchCriteria); // 执行聚合操作,返回结果列 AggregationResults<SomeResultClass> results = mongoOps.aggregate( Aggregation.newAggregation(lookupOperation, sortOperation, matchOperation), "table1", SomeResultClass.class); List<SomeResultClass> resultList = results.getMappedResults(); ``` 在上述示例代码中,通过定义LookupOperation实现了1和2的联查询,使用as方法指定了2的别名为"table2Alias";使用了SortOperation和MatchOperation操作,实现了按2别名中的某个字段排序和使用2中的某个字段作为条件过滤的功能。 最终通过调用MongoOperations的aggregate方法,执行聚合操作,并且将结果映射到SomeResultClass类中,返回了结果列

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值