select COMPANYNAME,CREATETIME from t_creditpromise;CREATETIME是DATE类型,传入字符串2023怎么查询
时间: 2024-02-24 18:59:50 浏览: 146
如果想查询 CREATETIME 字段中年份为 2023 的数据,则可以使用以下 SQL 语句:
```
SELECT COMPANYNAME, CREATETIME
FROM t_creditpromise
WHERE YEAR(CREATETIME) = 2023;
```
其中,`YEAR()` 函数可以从日期/时间表达式中提取年份,然后通过 `WHERE` 子句筛选出符合条件的数据。
相关问题
companyName_bringOut 如何用js去除这个字符串后面的_bringOut
你可以使用 JavaScript 的字符串截取方法 `substring` 或者 `slice` 去除 `_bringOut` 部分,例如:
```javascript
let companyName_bringOut = "ABC_company_bringOut";
let companyName = companyName_bringOut.substring(0, companyName_bringOut.indexOf("_bringOut"));
// 或者 let companyName = companyName_bringOut.slice(0, -10);
console.log(companyName); // 输出 "ABC_company"
```
以上代码中,`substring` 方法接受两个参数,分别是起始位置和结束位置(不包括结束位置),我们使用 `indexOf` 方法找到 `_bringOut` 的位置,从而得到要截取的字符串。
另外,你可以使用 `slice` 方法,该方法也接受两个参数,分别是起始位置和结束位置,但是它的第二个参数表示的是截取的长度(可以是负数,表示从后往前截取)。因此,你可以将第二个参数设为 `-10`,表示从后往前截取 10 个字符。
把这个查询条件用 myBatis-plus改写 <select id="selectALLBycondition" resultMap="TicketMap"> select * from t_ticket where <if test="companyName!=null and companyName!=''"> companyName like concat('%',#{companyName},'%') and </if> <if test="money!=null and money!=''"> money > #{money} and </if> <if test="subject!=null and subject!=''"> subject like concat('%',#{subject},'%') and </if> <if test="type!=null and type!=''"> type like concat('%',#{type},'%') and </if> status!='0' </select>
可以使用Mybatis-plus提供的QueryWrapper来实现条件查询,具体实现如下:
```
public List<Ticket> selectALLBycondition(String companyName, Double money, String subject, String type) {
QueryWrapper<Ticket> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", 1);
if (companyName != null && !"".equals(companyName)) {
queryWrapper.like("companyName", companyName);
}
if (money != null) {
queryWrapper.gt("money", money);
}
if (subject != null && !"".equals(subject)) {
queryWrapper.like("subject", subject);
}
if (type != null && !"".equals(type)) {
queryWrapper.like("type", type);
}
return ticketMapper.selectList(queryWrapper);
}
```
其中,QueryWrapper的eq方法表示等于,like方法表示模糊查询,gt方法表示大于。最后通过调用selectList方法,返回符合条件的Ticket对象列表。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![text/plain](https://img-home.csdnimg.cn/images/20250102104920.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)