select title,id from label where project_id = 42 and `status` = 1 and type = 0 order by id a inner join select title,id from label a where project_id = 42 and `status` = 1 and type = 4 order by listorder b on a.title = b.title
时间: 2023-12-14 17:39:15 浏览: 34
这是一条 SQL 查询语句,目的是从一个名为 "label" 的表中获取项目ID为42、类型为0、状态为1的标签的标题和ID,同时按照ID排序;然后将结果与另一个项目ID为42、类型为4、状态为1的标签按照指定顺序排序后的标题和ID进行内连接(即只返回两个表中都有的记录),并且连接条件是这两个表中的标签标题相同。
但是,该查询语句存在语法错误,应该将 "order by id" 和 "inner join" 中间的 "a" 删除。正确的查询语句如下:
```
select a.title, a.id from label a inner join
(select title, id from label where project_id = 42 and `status` = 1 and type = 4 order by listorder) b
on a.title = b.title
where a.project_id = 42 and a.status = 1 and a.type = 0
order by a.id
```
相关问题
select sum(order_amt) from source_pay_info where epay_status='0' and contract_no='' and link_id = 1
这是一个 SQL 查询语句,用于从 `source_pay_info` 表中查询符合条件的订单金额总和。
查询条件如下:
- `epay_status` 等于 '0'
- `contract_no` 为空字符串
- `link_id` 等于 1
查询语句如下:
```
SELECT SUM(order_amt) FROM source_pay_info WHERE epay_status='0' AND contract_no='' AND link_id = 1;
```
该查询将返回满足条件的订单金额总和。
SELECT COUNT(work_id) FROM hephaestus_work_notify_style_relation WHERE notify_style_id=4 and delete_status=0 合并work_id字段相同的数据
你的问题是关于SQL语句的,这是一种用来操作关系型数据库的语言。根据你的描述,你想要查询`hephaestus_work_notify_style_relation`表中`notify_style_id`为4且`delete_status`为0的记录,然后统计`work_id`字段不同的数量。如果你想要合并`work_id`字段相同的数据,可以使用GROUP BY子句和聚合函数SUM(),如下所示:
```
SELECT work_id, SUM(1) as count
FROM hephaestus_work_notify_style_relation
WHERE notify_style_id=4 and delete_status=0
GROUP BY work_id
```
这条SQL语句将会返回每个`work_id`出现的次数,结果会按照`work_id`进行分组,并且统计每组的行数。
相关推荐
![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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)