我有一个由cat_id
列链接的两个表。我想检索 M_Master 中timing
的所有值, Tbl_Appointment 中没有等效值。
示例: Tbl_Appointment 包含timing
值6:15 PM
的数据。除了timing
之外,我希望 M_Master 中的所有6:15 PM
值。
以下是来自 M_Master
的数据| id | name | timing | cat_id | rate | design_template | type | prefix | vat | | 109 | | 09:30 AM | 3 | 0 | | TIMING | | 0 | | 110 | | 09:45 AM | 3 | 0 | | TIMING | | 0 | | 113 | | 10:15 AM | 3 | 0 | | TIMING | | 0 | | 115 | | 11:00 AM | 3 | 0 | | TIMING | | 0 | | 116 | | 11:30 AM | 3 | 0 | | TIMING | | 0 | | 118 | | 12:30 PM | 3 | 0 | | TIMING | | 0 | | 121 | | 1:30 PM | 3 | 0 | | TIMING | | 0 | | 125 | | 2:30 PM | 3 | 0 | | TIMING | | 0 | | 127 | | 6:15 PM | 3 | 0 | | TIMING | | 0 |
这是来自 Tbl_Appointment
的数据| id | cancel | name | mobileno | age | sex | payment_told | test_id | referredby | app_given | sentsms | timing | cat_id | app_date | | 94 | 0 | TEST2 | 7985462313 | 45 | 1 | 800.00 | 123 | 14 | QWERTY | 1 | 06:15 PM | 3 | 2016-01-01 |
答案 0 :(得分:0)
根据目前提供的信息,您可以尝试
SELECT
DATE_FORMAT(M.timing, '%h:%i %p') AS timing
FROM M_Master M
JOIN Tbl_Appointment A
ON M.cat_id = A.cat_id
AND A.app_date = '2016-01-01'
AND M.timing != A.timing
ORDER BY M.timing
;
查看实际操作:SQL Fiddle。
请评论是否需要调整/进一步详细说明。