基于mysql中的另一个表单元格值排除的行

时间:2016-06-16 09:16:10

标签: mysql

我有两张桌子。

学生大师 enter image description here Feemaster enter image description here 我执行了查询

SELECT f.standard,fee_type,fee_name,amount,ac_year FROM fee_master f, student_master s
where
s.standard=f.standard and
s.admission_no='21300';

我得到了结果集 enter image description here

但我需要 如果studnet_master.ac_year == AC16 ,那么 INITIAL FEE 应该从结果集中删除,或者如果studnet_master.ac_year == != AC16 应该从结果集

中删除ADMISSION FEE

任何人都可以帮我解决这个问题....

提前致谢...

2 个答案:

答案 0 :(得分:3)

只需在WHERE子句中添加两个额外条件:

SELECT f.standard, f.fee_type, f.fee_name, f.amount, s.ac_year
FROM fee_master f
INNER JOIN
student_master s
    ON s.standard = f.standard
WHERE s.admission_no = '21300' AND
    (s.ac_year != 'AC16' OR f.fee_name != 'INITIAL FEES') AND
    (s.ac_year = 'AC16' OR f.fee_name != 'ADMISSION FEES')

答案 1 :(得分:0)

You can put condition in and statement.
Query:-
SELECT f.standard,fee_type,fee_name,amount,ac_year FROM fee_master f, student_master s
where
s.standard=f.standard and
s.admission_no='21300' and
IF(s.ac_year = 'AC16',FEE_NAME != 'INITIAL FEES',FEE_NAME != 'ADMISSION FEES')