求一查询语句

水哥阿乐 2010-10-22 10:55:41
现有表inp_bill_detail结构如下
patient_id char(10),
visit_id decimal(16, 0),
item_no decimal(16, 0),
item_class char(1),
item_name char(40),
item_code char(10),
amount decimal(16, 2),
units char(8),
ordered_by char(8),
performed_by char(8),
costs decimal(16, 2),
charges decimal(16, 2),
billing_date_time datetime,
operator_no char(4),
rcpt_no char(8),
st_date datetime,
settle_indicator char(1),
class_on_inp_rcpt char(1));
查询有几个要求ordered_by='030302'和item_name = '头孢克肟片'还有日期字段Billing_Date_time必须指定在2010-9-20到2010-10-20这期间,我组织的查询用了好几个and后没有返回查询结果
...全文
98 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ngx20080110 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wtuqi 的回复:]
引用 1 楼 dawugui 的回复:
SQL code
select * from inp_bill_detail
where ordered_by='030302' and item_name = '头孢克肟片' and to_char(Billing_Date_time,'YYYY-MM-DD') between '2010-09-20' and '2010-10-20'

看似挺……
[/Quote]
你怎麼知道數據庫確實有哪些數據呢?
水哥阿乐 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dawugui 的回复:]
SQL code
select * from inp_bill_detail
where ordered_by='030302' and item_name = '头孢克肟片' and to_char(Billing_Date_time,'YYYY-MM-DD') between '2010-09-20' and '2010-10-20'
[/Quote]
看似挺简单的,我也是这么查的甚至我怕没有这种药我把and item_name = '头孢克肟片'去掉了,也没有返回查询值.但数据库里面的确有这些数据.
  • 打赏
  • 举报
回复
--把你的sql语句列出来
select *
from inp_bill_detail
where ordered_by='030302'
and item_name = '头孢克肟片'
and Billing_Date_time
between to_date('2010-09-20','yyyy-mm-dd')
and to_date('2010-10-20','yyyy-mm-dd');
gelyon 2010-10-22
  • 打赏
  • 举报
回复
如果查询条件语句是正确的 ,没结果查询出来,那么你表中是否存在这样的记录啊!
Diza1986 2010-10-22
  • 打赏
  • 举报
回复
datetime类型那个注意类型的转换
没别的问题
心中的彩虹 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 wtuqi 的回复:]
现有表inp_bill_detail结构如下
patient_id char(10),
visit_id decimal(16, 0),
item_no decimal(16, 0),
item_class char(1),
item_name char(40),
item_code char(10),
amount decimal(16, 2),
units char(8),……
[/Quote]




select * from inp_bill_detail
where trim(ordered_by)='030302' and trim(item_name) = '头孢克肟片' and Billing_Date_time between to_date('2010-09-20','YYYY-MM-DD') and to_date('2010-10-20','YYYY-MM-DD')




gelyon 2010-10-22
  • 打赏
  • 举报
回复

--写了下,不知道有没有结果:
select * from inp_bill_detail
where ordered_by='030302' and item_name = '头孢克肟片'
and Billing_Date_time between to_date('2010-09-20','YYYY-MM-DD') and to_date('2010-10-20','YYYY-MM-DD');
齊麟 2010-10-22
  • 打赏
  • 举报
回复

select * from inp_bill_detail where ordered_by='030302' and item_name = '头孢克肟片' and Billing_Date_time ...

[Quote=引用楼主 wtuqi 的回复:]
我组织的查询用了好几个and后没有返回查询结果[/Quote]
不是吧,兰州?貌似很简单的,没有结果返回不正常?是不是数据库中根本就没有符合条件的数据啊?
ngx20080110 2010-10-22
  • 打赏
  • 举报
回复
select *
from inp_bill_detail
where ordered_by='030302'
and item_name = '头孢克肟片'
and Billing_Date_time between to_date('2010-09-20','yyyy-mm-dd') and to_date('2010-10-20','yyyy-mm-dd');

沒查詢到數據,可能是表中確實沒有相應的數據。
dawugui 2010-10-22
  • 打赏
  • 举报
回复
select * from inp_bill_detail
where ordered_by='030302' and item_name = '头孢克肟片' and to_char(Billing_Date_time,'YYYY-MM-DD') between '2010-09-20' and '2010-10-20'

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧