[英]Getting ERROR:1241 (21000): Operand should contain 1 column(s)?
SELECT CONCAT(Staff.fName, ' ', Staff.lName) AS 'Name', Staff.jobRole AS 'Job', Volunteer.firstAid AS 'First Aid?',(Volunteer.fName, ' ', Volunteer.lName) AS 'Name', Staff.contactNo AS 'Phone number', Volunteer.contactNo AS 'Phone number', Event.eventID, Event.eventName AS 'Event Name', Event.startDateTime AS 'Start Date/Time'
FROM EventStaff
JOIN Staff
ON Staff.staffID = EventStaff.staffID
JOIN Event
ON Event.eventID = EventStaff.eventID
JOIN EventVolunteer
ON EventVolunteer.eventID = Event.eventID
JOIN Volunteer
ON EventVolunteer.volunteerID = Volunteer.volunteerID
ORDER BY Event.startDateTime;
So I am trying to make a query for my table that involves 3 5 different tables (2 compounds) these are: Staff, Event, Volunteer, EventStaff and EventVolunteer. 因此,我试图查询涉及3 5个不同表(2个复合物)的表,它们是:Staff,Event,Volunteer,EventStaff和EventVolunteer。
The query I am trying to answer is: 我想回答的查询是:
"What staff and volunteers are attending what event and what are their job roles. Include if they are First aid qualified. Also provide first name and last name and their contact number and start date/time of the event." “什么员工和志愿者参加什么活动以及他们的工作角色。包括他们是否具备急救资格。还提供名字和姓氏以及他们的联系电话和活动的开始日期/时间。”
This error I keep getting I've looked around online but cant seem to resolve it. 我一直在网上浏览该错误,但似乎无法解决。
There is a CONCAT missing. 缺少CONCAT 。 You also can use CONCAT_WS(' ', field1,field2)
您还可以使用CONCAT_WS('',field1,field2)
SELECT
CONCAT(Staff.fName, ' ',
Staff.lName) AS 'Name',
Staff.jobRole AS 'Job',
Volunteer.firstAid AS 'First Aid?',
CONCAT(Volunteer.fName, ' ',
Volunteer.lName) AS 'Name',
Staff.contactNo AS 'Phone number', Volunteer.contactNo AS 'Phone number', Event.eventID, Event.eventName AS 'Event Name', Event.startDateTime AS 'Start Date/Time'
FROM EventStaff
JOIN Staff
ON Staff.staffID = EventStaff.staffID
JOIN Event
ON Event.eventID = EventStaff.eventID
JOIN EventVolunteer
ON EventVolunteer.eventID = Event.eventID
JOIN Volunteer
ON EventVolunteer.volunteerID = Volunteer.volunteerID
ORDER BY Event.startDateTime;
You could do something like this. 你可以做这样的事情。 Just make sure that the 2 select stamements have an equal number of columns.
只要确保2个选择的裁切具有相等的列数即可。 Hope this can help you further.
希望这可以为您提供进一步的帮助。
SELECT 'Staff Member' AS N, Staff.fName + ' ' + Staff.lName AS Name, Event.Id, Event.eventName, Event.startDateTime
FROM Staff
INNER JOIN EventStaff
ON Staff.staffId = EventStaff.staffId
INNER JOIN Event
ON Event.eventId = EventStaff.eventId
UNION ALL
SELECT 'Volunteer' AS N, Volunteer.fName + ' ' + Volunteer.lName AS Name, Event.Id, Event.eventName, Event.startDateTime
FROM Volunteer
INNER JOIN EventVolunteer
ON Volunteer.staffId = EventVolunteer.staffId
INNER JOIN Event
ON Event.eventId = EventVolunteer.eventId
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.