下面是我的问题
SELECT MONTHNAME(j.`date_in`)MONTH,
SUM(CASE WHEN MONTH(j.`date_in`) THEN 1 ELSE 0 END) TotalBookings,
SUM(CASE WHEN j.`status` = 1 THEN 1 ELSE 0 END) NoShows,
SUM(CASE WHEN j.`status` = 5 THEN 1 ELSE 0 END) Deleted,
SUM(CASE WHEN jd.`division` IN(494,489,488,487,486,485,484,483,482,481,492,490,479,478,493,491,477,476,475,474,473,495,496) THEN 1 ELSE 0 END) Services,
SUM(CASE WHEN jd.`division` IN(514,529,544,559,574,589,604,619,634,649,664,679,694,709,724,739,754,769,784,799,814,829,844,515,516,517,518,519,520,521,522,523,524,525,526,527,528,530,531,532,533,534,535,536,537,538,539,540,541,542,543,545,546,547,548,549,550,551,552,
553,554,555,556,557,558,560,561,562,563,564,565,566,567,568,569,570,571,572,573,575,576,577,578,579,580,581,582,583,584,585,586,587,588,590,591,592,593,594,595,
596,597,598,599,600,601,602,603,605,606,607,608,609,610,611,612,613,614,615,616,617,618,620,621,622,623,624,625,626,627,628,629,630,631,632,633,635,636,637,638,
639,640,641,642,643,644,645,646,647,648,650,651,652,653,654,655,656,657,658,659,660,661,662,663,665,666,667,668,669,670,671,672,673,674,675,676,677,678,680,681,
682,683,684,685,686,687,688,689,690,691,692,693,695,696,697,698,699,700,701,702,703,704,705,706,707,708,710,711,712,713,714,715,716,717,718,719,720,721,722,723,
725,726,727,728,729,730,731,732,733,734,735,736,737,738,740,741,742,743,744,745,746,747,748,749,750,751,752,753,755,756,757,758,759,760,761,762,763,764,765,766,
767,768,770,771,772,773,774,775,776,777,778,779,780,781,782,783,785,786,787,788) THEN 1 ELSE 0 END) Repairs
FROM jobcard j
INNER JOIN (SELECT jobcard,job_definition FROM job GROUP BY jobcard,job_definition) jb ON j.`id` = jb.`jobcard`
JOIN job_definition jd
ON jb.`job_definition` = jd.`id`
WHERE DATE(j.`date_in`) BETWEEN '2017-01-01'
AND '2017-12-31'
GROUP BY MONTH(j.`date_in`);
如果我在没有任何连接的情况下拉这个查询,结果会达到大约600个,但是如果我把它放在一个连接中,结果会达到大约4000个,我知道问题是因为它现在复制了我的jobcard条目以适应job条目,因为jobcard在job中不是唯一的。
有没有一种方法,你只能选择一个条目从工作卡,即使有多个条目在工作?
暂无答案!
目前还没有任何答案,快来回答吧!