当我在下面插入代码时
select (select i.billsec from isp_cdr i) *
(select l.user_rate from lcr l ) as nibble_total_billed
where i.destination_number !~'1548749'
and i.destination_number ~'^(?:[0-7] ?){6,14}[0-9]$' = l.digits;
我收到这个错误
错误:缺少表"i"的FROM子句条目
第2行:其中i.destination_number!~'1548749'
isp_cdr表:
destination_number
nibble_total_billed
caller_id
billsec
lcr表:
user_rate
digits
数字是电话号码destination_number是用户调出的电话号码
此查询的目的是计算带有国家代码(数字(的账单检查,然后使用user_rate将billsec更新乘以半字节_total_billed
样本数据
isp_cdr表
destination_number billsec
60161234587 50
60134812315 127
60147123512 98
lcr表
digits user_rate
601 0.15
4672 1.6
61891010 1.69
我不清楚你想在这里实现什么。
回答您为什么会出现错误的直接问题。
你的陈述基本上是这样的:
select (..) * (...) as nibble_total_billed
-- you are missing a FROM after the SELECT
where i.destination_number !~'1548749'
and i.destination_number ~'^(?:[0-7] ?){6,14}[0-9]$' = l.digits;
看起来您正在寻找两个表之间的连接:
select i.billsec * l.user_rate as nibble_total_billed
from isp_cdr i
join l.user_rate from l on i.destination_number = l.digits
where i.destination_number !~ '1548749'
and i.destination_number ~'^(?:[0-7] ?){6,14}[0-9]$'
给定(无效(条件i.destination_number ~'^(?:[0-7] ?){6,14}[0-9]$' = l.digits
,在将其与列digits
进行比较之前,您似乎想以某种方式"清理"destination_number
,但由于您没有显示任何示例数据,因此无法回答该部分问题。