我有一个包含symbol
属性的表。我想在symbol
值的某个位置解析我期望的某组字母的symbol
属性,并将它们与从子查询返回的解析值进行比较。这是我到目前为止的查询:
select * from market_instrument inner join exchange_instrument on market_instrument.id = exchange_instrument.instrument_id
inner join Table1 on market_instrument.id = Table1.instrument_id
left join Table2 on market_instrument.id = Table2.instrument_id
left join `options`on market_instrument.id = `options`.instrument_id
left join Table3 on market_instrument.id = Table3.instrument_id
where symbol in (select symbol from market_instrument inner join fills on market_instrument.id = fills.instrument_id);
这样做会将外部查询的symbol
属性与内部查询中的symbol
属性进行比较。 symbol
中的值如下所示:
1FU_PLAT_1610
我只想比较该值的一个子集。我可以做...where symbol[1:5] in (select symbol[1:5] from market_instrument inner join fills on market_instrument.id = fills.instrument_id);
之类的事情吗?
答案 0 :(得分:2)
使用SQL substring()
函数:
select * from market_instrument inner join exchange_instrument on market_instrument.id = exchange_instrument.instrument_id
inner join Table1 on market_instrument.id = Table1.instrument_id
left join Table2 on market_instrument.id = Table2.instrument_id
left join `options`on market_instrument.id = `options`.instrument_id
left join Table3 on market_instrument.id = Table3.instrument_id
where substring(symbol, 1, 5) in (select substring(symbol, 1, 5) from market_instrument inner join fills on market_instrument.id = fills.instrument_id);