SELECT U.USERNAME ,PT.SYS_CODE FROM T_USER_USER U LEFT JOIN T_ORGANIZATION O ON U.ORG_GUID=O.GUID LEFT JOIN B1_PARTY_ADMINISTRATIVE P ON U.PARTY_GUID = P.GUID LEFT JOIN B1_PARTY_EMPLOYEE E ON U.GUID = E.USER_GUID LEFT JOIN b1_develop_applicant DA ON DA.USER_GUID = U.GUID LEFT JOIN b1_employee_info EI ON EI.USER_GUID = U.GUID LEFT JOIN t_system_code PT ON PT.GUID = E.PERSON_TYPE WHERE 1=1 and t_system_code.SYS_CODE = 'zsdy' 这个sql有错误么
时间: 2023-11-27 17:51:40 浏览: 80
这个 SQL 有一个错误,即最后一行的 WHERE 子句中引用了表别名 t_system_code,但是在查询中没有使用该别名,应该将它替换为正确的别名。正确的 SQL 如下:
```
SELECT U.USERNAME, PT.SYS_CODE
FROM T_USER_USER U
LEFT JOIN T_ORGANIZATION O ON U.ORG_GUID = O.GUID
LEFT JOIN B1_PARTY_ADMINISTRATIVE P ON U.PARTY_GUID = P.GUID
LEFT JOIN B1_PARTY_EMPLOYEE E ON U.GUID = E.USER_GUID
LEFT JOIN b1_develop_applicant DA ON DA.USER_GUID = U.GUID
LEFT JOIN b1_employee_info EI ON EI.USER_GUID = U.GUID
LEFT JOIN t_system_code PT ON PT.GUID = E.PERSON_TYPE
WHERE 1=1
AND PT.SYS_CODE = 'zsdy'
```
相关问题
SELECT U.USERNAME ,t_system_code.SYS_CODE FROM T_USER_USER U LEFT JOIN T_ORGANIZATION O ON U.ORG_GUID=O.GUID LEFT JOIN B1_PARTY_ADMINISTRATIVE P ON U.PARTY_GUID = P.GUID LEFT JOIN B1_PARTY_EMPLOYEE E ON U.GUID = E.USER_GUID LEFT JOIN b1_develop_applicant DA ON DA.USER_GUID = U.GUID LEFT JOIN b1_employee_info EI ON EI.USER_GUID = U.GUID LEFT JOIN t_system_code PT ON PT.GUID = E.PERSON_TYPE WHERE 1=1 and t_system_code.SYS_CODE = 'zsdy' 这个sql有错误么
这个 SQL 语句可能会有错误,具体取决于你的数据库表结构和数据。这里有一些可能存在的问题:
1. `t_system_code` 表的别名 `t_system_code` 没有在 `FROM` 子句中出现过,需要添加该表的别名或者修改 `LEFT JOIN` 子句。
2. `t_system_code.SYS_CODE` 被用作筛选条件,但是没有指定它属于哪个表。如果 `SYS_CODE` 列存在于多个表中,需要指定所要筛选的表。
3. 筛选条件中的字符串应该使用单引号括起来,即 `t_system_code.SYS_CODE = 'zsdy'`。
因此,修改后的 SQL 语句如下:
```
SELECT U.USERNAME, t_system_code.SYS_CODE
FROM T_USER_USER U
LEFT JOIN T_ORGANIZATION O ON U.ORG_GUID=O.GUID
LEFT JOIN B1_PARTY_ADMINISTRATIVE P ON U.PARTY_GUID = P.GUID
LEFT JOIN B1_PARTY_EMPLOYEE E ON U.GUID = E.USER_GUID
LEFT JOIN b1_develop_applicant DA ON DA.USER_GUID = U.GUID
LEFT JOIN b1_employee_info EI ON EI.USER_GUID = U.GUID
LEFT JOIN t_system_code ON t_system_code.GUID = E.PERSON_TYPE
WHERE t_system_code.SYS_CODE = 'zsdy';
```
注意,这里我假设了 `t_system_code.SYS_CODE` 列属于 `t_system_code` 表。如果这个假设不成立,你需要根据实际情况修改查询。
阅读全文