T0.quote_name截取第一个点到第三个点之间的内容=T1.bond_name 写sql
时间: 2024-03-24 12:41:35 浏览: 46
您好,根据您的要求,可以使用如下的SQL语句来实现:
```
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(T0.quote_name, '.', 3), '.', -1) AS bond_name
FROM T0;
```
其中,`SUBSTRING_INDEX()`函数用于截取字符串中某个分隔符之前或之后的内容,第一个参数为待截取的字符串,第二个参数为分隔符,第三个参数为截取的次数(正数表示从左往右数,负数表示从右往左数)。
具体来说,这个SQL语句中先使用`SUBSTRING_INDEX(T0.quote_name, '.', 3)`截取第一个点到第三个点之间的内容,然后再使用`SUBSTRING_INDEX(..., '.', -1)`截取最后一个点之后的内容,即为所需的债券名称。
相关问题
FROM bobm, bordt, bopdt, bocpd WHERE bobm.bond_code=bordt.bond_code(+) AND bobm.bond_code =bopdt.bond_code(+) AND bobm.bond_code =bocpd.bond_code(+);
这是一个 SQL 查询语句,它使用了表之间的连接操作符(+)来表示左外连接。这个查询从四个表中获取数据:bobm、bordt、bopdt和bocpd。它使用了bobm表中的bond_code列来连接这些表。
左外连接表示将左边的表(bobm)中的所有行都包括在结果中,而右边的表(bordt, bopdt, bocpd)中只包括与左边表中的行匹配的行。如果没有匹配的行,则右边的表中的列将包含NULL值。
请注意,我的回答是基于对您提供的SQL查询的理解,如果有任何误解或遗漏,请及时纠正。
SET @batch_date = '20230222'; set @partition_name=concat('p',@batch_date); set @stat=concat('alter table tb_bond_price_comparision_reuslt truncate partition ',@partition_name); prepare stmt from @stat; execute stmt; insert into tb_bond_price_comparision_reuslt select distinct org.ISIN, mul.Broker_Yield, mul.Broker_Price, org.MARKET_PRICE, case when org.MARKET_PRICE > mul.Broker_Price then 'Broker Price' else 'BVAL' end as MARKET_PRICE_MIN, org.TRADE_REF, case when org.MARKET_PRICE > mul.Broker_Price then mul.Broker_Price else org.MARKET_PRICE end as MARKET_PRICE_MIN, case when org.MARKET_PRICE > mul.Broker_Price then mul.Broker_Price * org.NOMINAL_AMT else org.MARKET_PRICE * org.NOMINAL_AMT end as MARKET_VALUE_MIN, org.dt from tb_trade_blotter_op_sec org left join tb_bond_price_comparision_trade_blotter_op_sec_mul mul on org.TRADE_REF = mul.TRADE_REF and org.ISIN = mul.ISIN and org.dt = mul.dt where org.dt = @batch_date转换为mybatis执行语句以及生成service层代码
首先,将SQL语句转换为MyBatis执行语句:
```sql
<insert id="insertBondPriceComparisonResult" parameterType="string">
SET @batch_date = #{batchDate};
SET @partition_name = CONCAT('p', @batch_date);
SET @stat = CONCAT('ALTER TABLE tb_bond_price_comparision_reuslt TRUNCATE PARTITION ', @partition_name);
PREPARE stmt FROM @stat;
EXECUTE stmt;
INSERT INTO tb_bond_price_comparision_reuslt
SELECT DISTINCT
org.ISIN,
mul.Broker_Yield,
mul.Broker_Price,
org.MARKET_PRICE,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN 'Broker Price'
ELSE 'BVAL'
END AS MARKET_PRICE_MIN,
org.TRADE_REF,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN mul.Broker_Price
ELSE org.MARKET_PRICE
END AS MARKET_PRICE_MIN,
CASE
WHEN org.MARKET_PRICE > mul.Broker_Price THEN mul.Broker_Price * org.NOMINAL_AMT
ELSE org.MARKET_PRICE * org.NOMINAL_AMT
END AS MARKET_VALUE_MIN,
org.dt
FROM tb_trade_blotter_op_sec org
LEFT JOIN tb_bond_price_comparision_trade_blotter_op_sec_mul mul
ON org.TRADE_REF = mul.TRADE_REF AND org.ISIN = mul.ISIN AND org.dt = mul.dt
WHERE org.dt = @batch_date;
</insert>
```
然后,生成对应的Service层代码:
```java
@Service
public class BondPriceComparisonResultServiceImpl implements BondPriceComparisonResultService {
@Autowired
private BondPriceComparisonResultMapper bondPriceComparisonResultMapper;
@Override
public void insertBondPriceComparisonResult(String batchDate) {
bondPriceComparisonResultMapper.insertBondPriceComparisonResult(batchDate);
}
}
```
阅读全文