gpt4 book ai didi

mysql - 为mysql中的两个不同字段获取相同的名称

转载 作者:行者123 更新时间:2023-11-29 12:20:00 24 4
gpt4 key购买 nike

这是我选择的查询,我想两次获取相同的字段名称 processNm 和在 nxtProcess 中,我想从 processmaster 获取名称,但我没有得到任何输出

在我的进程表中,我有两个相同的字段processMasterId,nextProcessId,在这个字段中,从processmaster表插入相同的ID,我想获取他的名字。但我无法得到任何输出..

SELECT designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,SUM(moldNo) AS moldNo
,mold,status,processNm AS preProcess,processNm AS nxtProcess,nextProcessId
FROM designMaster,item,moldmaster,processmaster,process
WHERE item.itemId = designMaster.itemId
AND process.processMasterId = process.nextProcessId
AND process.designMasterId = designMaster.designMasterId
AND moldmaster.designMasterId = designMaster.designMasterId
AND processmaster.processMasterId = designMaster.nextProcess
GROUP BY designMaster.designMasterId
ORDER BY designMaster.designMasterId

最佳答案

您的查询无效。您使用 GROUP BY 的方式不正确。除 SUM() 之外的所有列都需要成为该组的一部分。

create table designMaster (
designMasterId number,
nextProcess number,
itemId number,
dNo number
);

create table item (
itemId number,
itemnm number
);

create table moldmaster (
designMasterId number,
moldNo number,
mold number
);

create table process (
processId number,
processMasterId number,
processDate date,
workerId number,
designMasterId number,
desWet number,
dWet number,
rDate date,
reciveWet number,
rejWet number,
nextProcessId number,
status number
);

create table processmaster (
processMasterId number,
processNm number,
sequence number
);

SELECT designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,SUM(moldNo) AS moldNo
,mold,status,processNm AS preProcess,processNm AS nxtProcess,nextProcessId
FROM designMaster,item,moldmaster,processmaster,process
WHERE item.itemId = designMaster.itemId
AND process.processMasterId = process.nextProcessId
AND process.designMasterId = designMaster.designMasterId
AND moldmaster.designMasterId = designMaster.designMasterId
AND processmaster.processMasterId = designMaster.nextProcess
GROUP BY designMaster.designMasterId,dNo,dWet,nextProcess,itemnm,mold,status,processNm,nextProcessId
ORDER BY designMaster.designMasterId;

关于mysql - 为mysql中的两个不同字段获取相同的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com