select (select sc_machid as ClinicID,
case
when substring(sc_machid,1,3)='BB0' then 'Head Office'
WHEN substring(sc_machid,1,3)='BA0' THEN 'HeadOffice'
when substring(sc_machid,1,3)='BA1' THEN 'Villiers'
when substring(sc_machid,1,3)='BA2' then 'Imperial IDC'
WHEN substring(sc_machid,1,3)='BA3' THEN 'Warden'
WHEN substring(sc_machid,1,3)='BA4' THEN 'Harrismith'
WHEN substring(sc_machid,1,3)='BA5' THEN 'Tugela'
WHEN substring(sc_machid,1,3)='BA6' THEN 'MooiRiver'
WHEN substring(sc_machid,1,3)='bad' THEN 'MooiRiver'
WHEN substring(sc_machid,1,3)='BB0' THEN 'Port Elizabeth'
WHEN substring(sc_machid,1,3)='BB1' THEN 'East London'
when substring(sc_machid,1,3)='BB2' THEN 'Umthatha'
when substring(sc_machid,1,3)='BB3' then 'Kokstad'
WHEN substring(sc_machid,1,3)='BB4' THEN 'Marian Hill'
WHEN substring(sc_machid,1,3)='BB5' THEN 'Zeerust'
WHEN substring(sc_machid,1,3)='BC0' THEN 'Imperial SBD'
WHEN substring(sc_machid,1,3)='BC1' THEN 'Imperial TSD'
WHEN substring(sc_machid,1,3)='BC2' THEN 'Roodekop'
WHEN substring(sc_machid,1,3)='BD0' THEN 'Ventersburg'
WHEN substring(sc_machid,1,3)='BD1' THEN 'Colesburg'
WHEN substring(sc_machid,1,3)='BD2' THEN 'Hanover'
WHEN substring(sc_machid,1,3)='BD3' THEN 'Beaufort West'
WHEN substring(sc_machid,1,3)='BD4' THEN 'Beit Bridge Border Post Musina'
WHEN substring(sc_machid,1,3)='BD5' THEN 'Cape Town - Epping'
WHEN substring(sc_machid,1,3)='BD7' THEN 'Komati Poort'
end as ClinicName, count(TransactionType) as NumberOfFirstTimePatientVisits
from sc_audit
where TransactionType = 'Insert Patient Record'
group by ClinicName)
as t1,
(
select pat_id as PatientID,
count(*) as NumberOfVisits,
sc_clinicid as ClinicID,
CASE
WHEN sc_clinicid = 'BA0' THEN 'HeadOffice'
when sc_clinicid = 'BA1' THEN 'Villiers'
when sc_clinicid = 'BA2' then 'Imperial IDC'
WHEN sc_clinicid = 'BA3' THEN 'Warden'
WHEN sc_clinicid = 'BA4' THEN 'Harrismith'
WHEN sc_clinicid = 'BA5' THEN 'Tugela'
WHEN sc_clinicid = 'BA6' THEN 'MooiRiver'
WHEN sc_clinicid = 'bad' THEN 'MooiRiver'
WHEN sc_clinicid = 'BB0' THEN 'Port Elizabeth'
WHEN sc_clinicid = 'BB1' THEN 'East London'
when sc_clinicid = 'BB2' THEN 'Umthatha'
when sc_clinicid = 'BB3' then 'Kokstad'
WHEN sc_clinicid = 'BB4' THEN 'Marian Hill'
WHEN sc_clinicid = 'BB5' THEN 'Zeerust'
WHEN sc_clinicid = 'BC0' THEN 'Imperial SBD'
WHEN sc_clinicid = 'BC1' THEN 'Imperial TSD'
WHEN sc_clinicid = 'BC2' THEN 'Roodekop'
WHEN sc_clinicid = 'BD0' THEN 'Ventersburg'
WHEN sc_clinicid = 'BD1' THEN 'Colesburg'
WHEN sc_clinicid = 'BD2' THEN 'Hanover'
WHEN sc_clinicid = 'BD3' THEN 'Beaufort West'
WHEN sc_clinicid = 'BD4' THEN 'Beit Bridge Border Post Musina'
WHEN sc_clinicid = 'BD5' THEN 'Cape Town - Epping'
WHEN sc_clinicid = 'BD7' THEN 'Komati Poort'
end as ClinicName
from sc_queue
group by ClinicName
)
as t2;
上述查詢給我,說操作數應包含1column(S)
Operand should contain 1column(s)
請幫我一個錯誤,我似乎無法找出問題的所在
它看起來像你的內部選擇應該是第一個選擇的參數,而不是選擇的列。 – Lidor
這是什麼樣的查詢? – diEcho
你應該爲這兩個case語句創建一個[function](http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html),假設它們實際上應該是相同的。另外,你可以說'CASE sc_clinicid WHEN ...'並且隨處移除'sc_clinicid ='。 – Dukeling