外键关联查询

最后更新:2024-09-18 05:30:10 | 状态:未完成
如学生表中有班级ID,查询时需要把班级名称查出来。除了用TableBuilder.left方式外也可以
RunPrepare prepare = TableBuilder.init("HR_USER").foreign("TYPE_CODE", "HR_TYPE", "CODE", "NAME", "TYPE_NAME").build();
ServiceProxy.querys(prepare);
    // SQL:
    SELECT
	HR_TYPE.NAME AS TYPE_NAME, HR_USER.*
    FROM HR_USER
    LEFT JOIN HR_TYPE ON HR_USER.TYPE_CODE = HR_TYPE.CODE
//也可以指定别名 及其他关联条件
prepare = TableBuilder.init("HR_USER AS U").foreign("TYPE_CODE", "HR_TYPE AS T", "CODE", "NAME", "TYPE_NAME", "U.ID > 0").build();
ServiceProxy.querys(prepare);
   // SQL
    SELECT 
	T.NAME AS TYPE_NAME, U.*
    FROM HR_USER AS U
    LEFT JOIN HR_TYPE AS T ON (U.TYPE_CODE = T.CODE AND U.ID > 0)

首页 最近更新 搜索 提交 回复