SELECT `Good`.`id`, `Good`.`name`, `Good`.`a.category.id` FROM `Good` WHERE `Good`.`a.category.id` IN (SELECT `Good`.`id` FROM `Good` WHERE `Good`.`name` = '摩托罗拉W380'); 1054 - Unknown column 'Good.a.category.id' in 'field list' 如何解决
时间: 2023-07-20 15:45:24 浏览: 30
根据错误提示,可以看出 `Good.a.category.id` 这个字段无法被识别。我猜想你想查询的是 `Good` 表中的 `category_id` 字段,而不是 `Good.a.category.id`。你可以尝试修改查询语句,将 `Good.a.category.id` 改为 `Good.category_id`,如下所示:
```
SELECT `Good`.`id`, `Good`.`name`, `Good`.`category_id` FROM `Good` WHERE `Good`.`category_id` IN (SELECT `Good`.`id` FROM `Good` WHERE `Good`.`name` = '摩托罗拉W380');
```
这样应该就可以解决这个问题了。
相关问题
case when a.id='1' from
It looks like your SQL statement is incomplete. The `CASE` statement is used to conditionally return a value based on one or more conditions. However, in your example, you only have the beginning of the statement (`CASE WHEN a.id='1' FROM`).
Assuming you want to return a specific value when `a.id` is equal to `'1'`, the correct syntax would be:
```
SELECT CASE WHEN a.id = '1' THEN 'Value when ID is 1' ELSE 'Value when ID is not 1' END as my_column
FROM my_table a
```
In this example, the `CASE` statement checks if `a.id` is equal to `'1'`. If it is, the value `'Value when ID is 1'` is returned. If it is not, the value `'Value when ID is not 1'` is returned. The result is returned as a column named `my_column` from the table `my_table` (which you will need to replace with your actual table name).
a.id这个不存在,报错
感谢您提供了更具体的错误信息。根据您提供的信息,可以发现 SELECT 子句中的 a.id 字段是不存在的,因此查询语句无法正确执行。
要解决这个问题,您需要检查查询语句中的表别名和字段名是否都正确。如果您想要在结果集中包含业务流程明细表(business_flow_detail)的 ID 列,可以尝试在 SELECT 子句中添加以下代码:
```
SELECT bfd.id AS id, a.*
```
这样就可以将业务流程明细表的 ID 列包含在结果集中,并使用别名 id 引用它。完整的查询语句可能如下所示:
```
SELECT bfd.id AS id, a.*
FROM (
SELECT DISTINCT
fcl.source_value,
bfd.goods_code AS goods_code,
bfd.goods_name AS goods_name,
bfd.specification AS goods_specification,
bfd.unit AS goods_unit,
bfd.sales_type AS order_type_name,
bfd.client_name AS hospital_name
FROM business_flow_detail bfd
INNER JOIN flow_clean_log fcl ON bfd.id = fcl.business_flow_detail_id
) a
```
请注意,这只是一种可能的解决方案,具体的修改方式还需要根据您的实际情况进行调整。