fix error in same name column reference "id" is ambiguous #3727
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
example:
CREATE TABLE IF NOT EXISTS
app
(
id
INT NOT NULL AUTO_INCREMENT,parent_app_id
INT NOT NULL DEFAULT 0 COMMENT '合并父应用id',PRIMARY KEY (
id
) USING BTREE) AUTO_INCREMENT = 105 COMMENT = 'API所属的应用信息';
CREATE TABLE IF NOT EXISTS
user_account
(id
BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键id',name
VARCHAR(255) COMMENT '账号名称',PRIMARY KEY (
id
) USING BTREE) AUTO_INCREMENT = 1 COMMENT='账号表,存储账号的基本信息和安全评分';
-- name: GetUserAccountAllChildIDs :exec
WITH app_user_account_id AS (
SELECT tua.id,
tua.name,
CAST(IFNULL(tb.id, ta.id) AS SIGNED) AS parent_app_id
FROM user_account AS tua
LEFT JOIN app AS ta ON ta.id = tua.app_id
LEFT JOIN app as tb ON ta.parent_app_id = tb.id
WHERE tua.masked_sign = 1 AND tua.deleted_sign = 1
AND ta.masked_sign = 1
AND ta.deleted_sign = 1
)
SELECT a.name
FROM app_user_account_id AS a
LEFT JOIN app_user_account_id AS b ON b.id IN (sqlc.slice('account_id_set')) AND a.name = b.name AND a.parent_app_id = b.parent_app_id;