我有两张桌子。
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';
但我需要 如果studnet_master.ac_year == AC16 ,那么 INITIAL FEE 应该从结果集中删除,或者如果studnet_master.ac_year == != AC16 则应该从结果集
中删除ADMISSION FEE任何人都可以帮我解决这个问题....
提前致谢...
答案 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')