select mg.id, mg.name, mg.category_id, mg.code, mg.brand_id, mg.stock, mg.is_hot_sell, mg.is_shelves, mg.is_new, mg.is_limit_buy_quantity, mg.is_open_group, mg.group_number, mg.group_lowest_price, mg.state, mg.main_pic, mg.keyword, mg.brief_introduction, mg.supply_channel, mg.supplier_id, mg.video_link, mg.description, mg.create_by, mg.create_time, mg.create_org, mg.update_by, mg.update_time, mg.made_in, mg.model, mg.market_price, mg.is_shipping_cost, mg.shipping_cost, mg.is_tax, mg.billing_type, mg.sell_count, (select name from mall_brand where id = mg.brand_id) brand_name, category_name, (select name from mall_supplier where id = mg.supplier_id) supplier_name, shelves_time, (select retail_price,unit_price from mall_goods_sku where goods_id=mg.id limit 1) retail_price,unit_price from mall_goods mg where mg.state = 1 这个sql语句哪里错了
时间: 2024-04-18 08:30:14 浏览: 152
这个 SQL 语句有一个错误。在子查询中,不能同时选择两个列 `retail_price` 和 `unit_price`。你需要分别选择它们,并在子查询中进行单独的选择。下面是修正后的 SQL 语句:
```sql
select mg.id, mg.name, mg.category_id, mg.code, mg.brand_id, mg.stock, mg.is_hot_sell, mg.is_shelves, mg.is_new, mg.is_limit_buy_quantity,
mg.is_open_group, mg.group_number, mg.group_lowest_price, mg.state, mg.main_pic, mg.keyword, mg.brief_introduction,
mg.supply_channel, mg.supplier_id, mg.video_link, mg.description, mg.create_by, mg.create_time, mg.create_org, mg.update_by,
mg.update_time, mg.made_in, mg.model, mg.market_price, mg.is_shipping_cost, mg.shipping_cost, mg.is_tax, mg.billing_type,
mg.sell_count,
(select name from mall_brand where id = mg.brand_id) brand_name,
category_name,
(select name from mall_supplier where id = mg.supplier_id) supplier_name,
shelves_time,
(select retail_price from mall_goods_sku where goods_id=mg.id limit 1) retail_price,
(select unit_price from mall_goods_sku where goods_id=mg.id limit 1) unit_price
from mall_goods mg
where mg.state = 1;
```
这个修正后的 SQL 语句会选择 `retail_price` 和 `unit_price` 作为单独的列,并且在子查询中进行单独的选择。
阅读全文