如何实现这样的SQL需求
本文介绍了如何实现这样的SQL需求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
图书数据,现在excel里有200个作者author和图书价格price,是一一对应关系,
比如:
张三 15.6
李四 20
想从数据库拿出书的名字book_name,改如何批量抓取?
如何使得author 和 price 一一对应
还有一点,如何模糊匹配,使得价格区间相差两块钱,比如张三, 挑出他的图书价格在 13.6-17.6的所有图书?
select book_name from db where
谢谢!
解决方案
假设数据库中有一张Book表字段是author book_name price
将excel的数据导入表A
select author,book_name,price from Book b where exists(select 1 from A a where a.author=b.author and a.price=b.price)
select author,book_name,price from Book b where exists(select 1 from A a where a.author=b.author and b.price>=a.price - 2 and b.price<=a.price + 2)
这篇关于如何实现这样的SQL需求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文