내 데이터베이스에 8 개의 테이블이 있고 그 중 하나의 쿼리에 필요한 모든 데이터가 있어야합니다. where
문을 사용하지 않을 경우 , 내 쿼리가 작동,하지만 난 내 쿼리 LIKE
및 OR LIKE
를 사용할 때 where
문이 제대로내 mysql 쿼리에서 제대로 작동하지 않습니다
내 원래 쿼리를 작동하지 않는 것은 :
SELECT `mhr_patients`.`id`,
`mhr_patients`.`fullName`,
`mhr_patients`.`nationalCode`,
`mhr_patients`.`age`,
`mhr_patients`.`firstGCS`,
`mhr_patients`.`fileNumber`,
`mhr_patients`.`isUnKnown`,
`mhr_patients`.`docDetail`,
`mhr_patients`.`presentation`,
`mhr_patients`.`appRegisterTime`,
`mhr_patients`.`inspectorRegisterTime`,
`mhr_patients`.`patientStatusDetail`,
`mhr_patients`.`patientDetail`,
`mhr_patients`.`status`,
`docT`.`text` AS docText,
`tolOp`.`name` AS tolOpName,
`tolOp`.`color` AS tolOpColor,
`tolOp`.`res1` AS tolOpTextColor,
`pLog`.`breathing`,
`pLog`.`bodyMovement`,
`pLog`.`faceMovement`,
`pLog`.`gag`,
`pLog`.`cough`,
`pLog`.`cornea`,
`pLog`.`pupil`,
`pLog`.`dollEye`,
`pLog`.`secondGCS`,
`pLog`.`sedation`,
`pLog`.`inspector`,
`pLog`.`status` As pLogStatus,
`pLog`.`section`,
`pLog`.`id` AS pLogId,
`pLog`.`typeOfSection`,
`pLog`.`lastUpdateTime`,
`pLog`.`isTransfer`,
`pLog`.`opu`,
`hos`.`name` AS hosName,
`mhr_opu`.`name` AS opuName,
`mhr_opu`.`id` AS opuId,
`mhr_states`.`name` AS cityName,
`mhr_inspectors`.`name` AS insName
FROM (`mhr_patients`)
JOIN `mhr_doc` AS docT ON `docT`.`id` = `mhr_patients`.`doc`
JOIN `mhr_tol_options` AS tolOp ON `tolOp`.`id` = `mhr_patients`.`patientStatus`
JOIN `mhr_patients_log` AS pLog ON `pLog`.`pId` = `mhr_patients`.`id` AND pLog.id = (SELECT MAX(mhr_patients_log.id) FROM mhr_patients_log WHERE mhr_patients_log.pId = mhr_patients.id)
JOIN `mhr_hospitals` AS hos ON `hos`.`id` = `pLog`.`hospital`
JOIN `mhr_opu` ON `mhr_opu`.`id` = `pLog`.`opu`
JOIN `mhr_states` ON `mhr_states`.`id` = `pLog`.`city`
JOIN `mhr_inspectors` ON `mhr_inspectors`.`id` = `pLog`.`inspector`
WHERE
`mhr_patients`.`status` = 5
GROUP BY `pLog`.`pId`
ORDER BY `mhr_patients`.`inspectorRegisterTime` asc
LIMIT 30
내가 사용하는 경우 위의 쿼리 결과가 정확하고 내가 변경할 때 mhr_patients
. status
, 다른 결과가 반환되지만 다음 쿼리를 사용할 때 mhr_patients
. status
은 작동하지 않고 어떤 매개 변수에도 관계없이 하나의 결과를 제공합니다.
SELECT `mhr_patients`.`id`,
`mhr_patients`.`fullName`,
`mhr_patients`.`nationalCode`,
`mhr_patients`.`age`,
`mhr_patients`.`firstGCS`,
`mhr_patients`.`fileNumber`,
`mhr_patients`.`isUnKnown`,
`mhr_patients`.`docDetail`,
`mhr_patients`.`presentation`,
`mhr_patients`.`appRegisterTime`,
`mhr_patients`.`inspectorRegisterTime`,
`mhr_patients`.`patientStatusDetail`,
`mhr_patients`.`patientDetail`,
`mhr_patients`.`status`,
`docT`.`text` AS docText,
`tolOp`.`name` AS tolOpName,
`tolOp`.`color` AS tolOpColor,
`tolOp`.`res1` AS tolOpTextColor,
`pLog`.`breathing`,
`pLog`.`bodyMovement`,
`pLog`.`faceMovement`,
`pLog`.`gag`,
`pLog`.`cough`,
`pLog`.`cornea`,
`pLog`.`pupil`,
`pLog`.`dollEye`,
`pLog`.`secondGCS`,
`pLog`.`sedation`,
`pLog`.`inspector`,
`pLog`.`status` As pLogStatus,
`pLog`.`section`,
`pLog`.`id` AS pLogId,
`pLog`.`typeOfSection`,
`pLog`.`lastUpdateTime`,
`pLog`.`isTransfer`,
`pLog`.`opu`,
`hos`.`name` AS hosName,
`mhr_opu`.`name` AS opuName,
`mhr_opu`.`id` AS opuId,
`mhr_states`.`name` AS cityName,
`mhr_inspectors`.`name` AS insName
FROM (`mhr_patients`)
JOIN `mhr_doc` AS docT ON `docT`.`id` = `mhr_patients`.`doc`
JOIN `mhr_tol_options` AS tolOp ON `tolOp`.`id` = `mhr_patients`.`patientStatus`
JOIN `mhr_patients_log` AS pLog ON `pLog`.`pId` = `mhr_patients`.`id` AND pLog.id = (SELECT MAX(mhr_patients_log.id) FROM mhr_patients_log WHERE mhr_patients_log.pId = mhr_patients.id)
JOIN `mhr_hospitals` AS hos ON `hos`.`id` = `pLog`.`hospital`
JOIN `mhr_opu` ON `mhr_opu`.`id` = `pLog`.`opu`
JOIN `mhr_states` ON `mhr_states`.`id` = `pLog`.`city`
JOIN `mhr_inspectors` ON `mhr_inspectors`.`id` = `pLog`.`inspector`
WHERE
`mhr_patients`.`status` = 5
AND `mhr_patients`.`fullName` LIKE '%aaa%'
OR `mhr_patients`.`nationalCode` LIKE '%aaa%'
OR `mhr_patients`.`fileNumber` LIKE '%aaa%'
OR `mhr_patients`.`age` LIKE 'aaa'
OR `mhr_patients`.`firstGCS` LIKE 'aaa'
OR `mhr_patients`.`patientDetail` LIKE '%aaa%'
GROUP BY `pLog`.`pId`
ORDER BY `mhr_patients`.`inspectorRegisterTime` asc
LIMIT 30
무엇이 문제입니까?
그것은 작동하고있어, 덕분에 ... 그것은 내 마음에 아니었다. 하지만 약간의 질문, 나는 codeigniter를 사용하고 나는 $ this-> db-> like(); 활성 레코드에서 내 쿼리에 (&)를 어떻게 추가합니까? – mhrezaei
죄송합니다, codeiginiter 모르겠다. 그것은 다른 질문입니다. 질문을 해결 한 경우이를 답변으로 표시하는 것을 잊지 마십시오. – Robbert