gpt4 book ai didi

mysql - 错误111,组函数使用无效

转载 作者:行者123 更新时间:2023-11-29 20:56:49 25 4
gpt4 key购买 nike

SELECT DISTINCT CONCAT('TOTAL NUMBER OF LEGS IN A TRIP NUMBER ', T1.TNUM, ' IS NOT EQUAL TO THE LARGEST NUMBER OF LEG IN THE TRIP') AS 'ERR'
FROM TRIPLEG T1
WHERE MAX(T1.LEGNUM) = (SELECT COUNT(T2.TNUM)
FROM TRIPLEG
WHERE T1.TNUM = T2.TNUM);

通过我的代码,我试图找到所有违反以下一致性约束的行程。每次行程的最后一段航程必须等于一次行程的总航段数"

CREATE TABLE TRIPLEG(
TNUM DECIMAL(10) NOT NULL,
LEGNUM DECIMAL(2) NOT NULL,
DEPARTURE VARCHAR(30) NOT NULL, DESTINATION VARCHAR(30) NOT NULL,
CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (TNUM, LEGNUM),
CONSTRAINT TRIPLEG_UNIQUE UNIQUE(TNUM, DEPARTURE, DESTINATION),
CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (TNUM) REFERENCES TRIP(TNUM) );

INSERT INTO TRIPLEG VALUES( 1, 1, 'Sydney', 'Melbourne');
INSERT INTO TRIPLEG VALUES( 1, 2, 'Melbourne', 'Hobart');

最佳答案

尝试以下操作;)

SELECT DISTINCT CONCAT('TOTAL NUMBER OF LEGS IN A TRIP NUMBER ', T1.TNUM, ' IS NOT EQUAL TO THE LARGEST NUMBER OF LEG IN THE TRIP') AS 'ERR'
FROM TRIPLEG T1
GROUP BY T1.TNUM
HAVING COUNT(T1.TNUM) <> MAX(T1.LEGNUM)

关于mysql - 错误111,组函数使用无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37559041/

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