Home > Backend Development > PHP Tutorial > 搜索A表在B表里没有数据的记录如何写SQL语句

搜索A表在B表里没有数据的记录如何写SQL语句

WBOY
Release: 2016-06-13 12:02:33
Original
1063 people have browsed it

搜索A表在B表里没有数据的记录怎么写SQL语句?
如:
A表
a_id       name   ........
   1         张三
  2         李四
  3         王五
  4         赵六


B表
b_id        a_id        total
1             1           100
2             3           200


 欠费


勾选上面的欠费提交后怎么搜索出李四和赵六????
------解决方案--------------------
因為王五有交費,且沒有欠費,所以不用顯示。
樓主應該是要找出未交費或有欠費的用戶
<br />select t1.name from a as t1 left join b as t2 on t1.a_id=t2.a_id where qianfei is null or qianfei>0;<br />
Copy after login

可以這樣寫,先left join,然後找出qianfei>0 或 qianfei為null的記錄即可。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template