使用以下查询我只需要在月份“02”中显示标有年份“2014”的记录:
SELECT DISTINCT
c.sno,
c.cCode,
c.caseNumber,
c.dateOriginalInstitution,
c.date_remanded,
c.plaintiff,
c.respondant
FROM
cases c,
chronologicallists ch
WHERE (
(YEAR(dateOriginalInstitution) = '2014' AND MONTH(dateOriginalInstitution) = '02')
OR
(YEAR(dateOfTransferInstituion) = '2014' AND MONTH(dateOfTransferInstituion) = '02')
OR
(YEAR(date_restored) = '2014' AND MONTH(date_restored) = '02')
)
AND c.inTheCourt = '578' AND c.sno = ch.caseSno
我仍然在结果集中获得2011年和2012年?
请帮助我。
答案 0 :(得分:5)
这是因为你的OR
条件。
year
或2014
列中的dateOfTransferInstituion
值date_restored
可能不是dateOriginalInstitution
列
答案 1 :(得分:0)
您需要检查的dateOriginalInstitution
,dateOfTransferInstituion
,dateOfTransferInstituion
共有3列
使用AND
而不是OR
,请注意显示dateOfTransferInstituion
,以便了解
他们通过了WHERE
条件。
WHERE (
(YEAR(dateOriginalInstitution) = '2014' AND MONTH(dateOriginalInstitution) = '02')
AND
(YEAR(dateOfTransferInstituion) = '2014' AND MONTH(dateOfTransferInstituion) = '02')
AND
(YEAR(date_restored) = '2014' AND MONTH(date_restored) = '02')