有人可以帮我重做这个查询,以便我可以获取outer_config.contractorsRef值。目前它没有找到价值。在代码中,我已经在下面高亮了。我有用countley写的查询与计数(*)和选择在一个子查询,因为它执行很快比计数(不同)。mysql查询 - 选择找不到值
SELECT outer_config.contractorsRef AS cref, outer_config.contractorsRef AS contractorsRef, noworkers
FROM bis.request_config AS outer_config
LEFT JOIN (
SELECT request_config.contractorsRef, (
SELECT COUNT(*) subcount
FROM (
SELECT DISTINCT subcontractorRef
FROM bis.Request
INNER JOIN bis.request_config ON request_config.RIDGROUP = request.RIDGROUP
AND currenttaxyear =2011
AND weekno =33
AND contractorsRef=outer_config.contractorsRef ############ERROR HERE###########
GROUP BY contractorsRef
)x
)noworkers
FROM bis.Request
INNER JOIN bis.request_config ON request_config.RIDGROUP = request.RIDGROUP
AND currenttaxyear =2011
AND weekno =33
)T1 ON T1.contractorsRef = outer_config.contractorsRef
WHERE currenttaxyear =2011
AND weekno =33
AND outer_config.contractorsRef <>132
GROUP BY outer_config.contractorsRef
表防守
-
CREATE TABLE request_config (
RIDGROUP int(11) NOT NULL AUTO_INCREMENT,
sessionstart text NOT NULL,
EmployeeID int(11) NOT NULL,
closedrequest tinyint(1) NOT NULL,
contractorsRef int(11) NOT NULL DEFAULT '0',
timesheetDateSubmited text,
requesttotal int(11) NOT NULL DEFAULT '0',
imported int(11) NOT NULL DEFAULT '0',
dateref text,
onlinespreadsheet int(11) NOT NULL DEFAULT '0',
marginamt double NOT NULL DEFAULT '0',
grossamt double NOT NULL DEFAULT '0',
feespaidbyclient int(11) NOT NULL DEFAULT '0',
currenttaxyear int(11) NOT NULL DEFAULT '0',
weekno int(11) NOT NULL DEFAULT '0',
subdedamt double NOT NULL DEFAULT '0',
timesheetfrequency int(11) NOT NULL DEFAULT '0',
onlinesubmission int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (RIDGROUP),
KEY contractorsRef_2 (contractorsRef,currenttaxyear,weekno)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE request (
RID int(11) NOT NULL,
RIDGROUP int(11) NOT NULL,
EmployeeID int(11) NOT NULL,
date_requested text NOT NULL,
hours double NOT NULL,
rate double NOT NULL,
agencydeduction double NOT NULL,
otherpay double NOT NULL,
totaltimesheet double NOT NULL,
subcontractorRef text NOT NULL,
candidatename text NOT NULL,
candidatename_sys text NOT NULL,
validated tinyint(1) NOT NULL DEFAULT '0',
requestclosed tinyint(1) NOT NULL DEFAULT '0',
paytypeID int(11) NOT NULL DEFAULT '0',
retrieved int(11) NOT NULL DEFAULT '0',
KEY RID (RID),
KEY RIDGROUP (RIDGROUP),
KEY subcontractorRef (subcontractorRef(20))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
CREATE TABLE contractors (
contractorsRef int(11) NOT NULL AUTO_INCREMENT,
contractorsName text,
contractName text,
TELEPHONE text,
MOBILE text,
FAX text,
contractorsAddress1 text,
contractorsAddress2 text,
contractorsAddress3 text,
contractorsAddress4 text,
contractorsAddress5 text,
contractorsAddresspostcode text,
emailaddress text,
websiteadd text,
Contractsent int(11) DEFAULT '0',
Contractreceived int(11) DEFAULT '0',
officeno int(11) DEFAULT '0',
clientID text,
jobtype int(11) DEFAULT '0',
weeknopaymentfilereceived int(11) DEFAULT '0',
timetogenerateemail text,
daytogenerateemail text,
weeknoremindersent int(11) DEFAULT '0',
weeknoremindersent_O2 int(11) DEFAULT '0',
disabledreminder int(11) DEFAULT '0',
active int(11) NOT NULL DEFAULT '0',
createdbyEmployeeID int(11) NOT NULL DEFAULT '0',
marginagreed double NOT NULL DEFAULT '0',
rebateagreed double NOT NULL DEFAULT '0',
marketing int(11) NOT NULL DEFAULT '0',
ARDENTORO2 int(11) NOT NULL DEFAULT '0',
www text,
clientID2 text,
attentionneeded int(11) NOT NULL DEFAULT '0',
UNREFCOUNTER int(11) NOT NULL DEFAULT '0',
feespaidbyclient int(11) NOT NULL DEFAULT '0',
request_manual_entry int(11) NOT NULL DEFAULT '0',
payupon int(11) NOT NULL DEFAULT '0',
weektostartreminder text,
reminder_duration int(11) NOT NULL DEFAULT '0',
dayofweekpaymentexpected int(11) NOT NULL DEFAULT '0',
Correspondence text,
timesheetfrequency int(11) NOT NULL DEFAULT '0',
atnc int(11) NOT NULL DEFAULT '0',
nextts_expected int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (contractorsRef),
KEY clientID (clientID(8))
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
请提供您的表格定义。 – Polynomial
添加的定义 – user984314