SELECT MAX(imagefileid) AS imagefileid FROM docimagefile WHERE docid=? AND docfiletype=12 GROUP BY id ORDER BY imagefileid DESC 修改sql 逻辑是 docfiletype 值为 3,6,7,12满足任意一个
时间: 2024-02-17 19:04:05 浏览: 27
你可以使用以下SQL查询语句来实现以上逻辑:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid=? AND docfiletype IN (3, 6, 7, 12)
GROUP BY id
ORDER BY imagefileid DESC
```
这条SQL语句中使用了IN操作符,它可以让我们查询docfiletype等于3、6、7或12的记录,从而实现了满足任意一个的逻辑要求。同时,GROUP BY条件按照id分组,ORDER BY条件按照imagefileid降序排序,最终返回每个id对应的最大imagefileid值。
相关问题
SELECT MAX(imagefileid) AS imagefileid FROM docimagefile WHERE docid=? AND docfiletype=12 GROUP BY id ORDER BY imagefileid DESC 改为 docfiletype = 3,6,7,12中任意一个即可
你的SQL查询语句可以改为以下任意一种:
1. 当docfiletype等于3时,SQL查询语句为:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid=? AND docfiletype=3
GROUP BY id
ORDER BY imagefileid DESC
```
2. 当docfiletype等于6时,SQL查询语句为:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid=? AND docfiletype=6
GROUP BY id
ORDER BY imagefileid DESC
```
3. 当docfiletype等于7时,SQL查询语句为:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid=? AND docfiletype=7
GROUP BY id
ORDER BY imagefileid DESC
```
4. 当docfiletype等于12时,SQL查询语句为:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid=? AND docfiletype=12
GROUP BY id
ORDER BY imagefileid DESC
```
请注意,以上SQL查询语句只是将原来的docfiletype条件改为了3、6、7或12。如果其他条件不变,可以直接使用上述查询语句,否则请根据实际情况进行修改。另外,原始SQL语句中的GROUP BY条件应该是按id分组,而不是按docfileid分组,已经做了相应修改。
select max(imagefileid) imagefileid from docimagefile where docid=? group by id order by imagefileid desc 只查 isextfile 为空的数据
您可以使用以下 SQL 语句来实现:
```
SELECT MAX(imagefileid) AS imagefileid
FROM docimagefile
WHERE docid = ? AND isextfile IS NULL
GROUP BY id
ORDER BY imagefileid DESC
```
这将只查询 isextfile 为空的数据,并按照 imagefileid 的降序排列,然后选择最大的 imagefileid。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)