我有一个类似的问题:
INSERT INTO groups(
participants, count1, count2, count3)
SELECT
0 as participants,
(count1/participants) as count1,
(count2/participants) as count2,
(count3/participants) as count3 WHERE id = 22;
现在,在表格中你有:
组
id participants count1 count2 count3
22 5 10000 10000 10000
该查询将插入具有以下值的新行:
id participants count1 count2 count3
23 0 2000 2000 2000
正如我所说的,它在工作台上工作得很好,但是如果我在jdbc(springjava)中运行,我会奇怪地发现这一点
id participants count1 count2 count3
23 0 2000 NULL NULL
这是实际查询或类似查询,这是原始查询,我只是通过上面的例子来帮助理解问题。
INSERT INTO registrations (
numberOfParticipants,
eventId,
eventName,
STATUS,
createdOn,
source,
sourceDetail,
paymentType,
groupId,
couponId,
eventModality,
eventHour,
groupName,
couponCode,
additionalProductQuantities,
productsPaid,
discount,
insurance,
baseTotal,
COMMENT,
processingFee,
isVolunteer,
participantType,
ipNumber,
refererCodeId
)
SELECT
0 AS numberOfParticipants,
(SELECT
eventId
FROM
groups
WHERE id = 27) AS eventId,
(SELECT
lastEventName
FROM
groups
WHERE id = 27) AS eventName,
STATUS,
createdOn,
source,
sourceDetail,
paymentType,
27,
couponId,
eventModality,
eventHour,
(SELECT
NAME
FROM
groups
WHERE id = 27) AS groupName,
couponCode,
additionalProductQuantities,
(
productsPaid / numberOfParticipants
) AS productsPaid,
(discount / numberOfParticipants) AS discount,
(insurance / numberOfParticipants) AS insurance,
(baseTotal / numberOfParticipants) AS baseTotal,
NULL,
(
processingFee / numberOfParticipants
) AS processingFee,
isVolunteer,
participantType,
ipNumber,
refererCodeId
FROM
registrations
WHERE id = 15787;
1条答案
按热度按时间htrmnn0y1#
您确定mysql查询的语法正确吗?它应该在查询中包含一个“from”语句。“group”也是mysql中的保留关键字。
没有提供足够的信息。这是我能给你的最好的了。也许共享java源代码可以帮助我们提供更好的解决方案。