gpt4 book ai didi

mysql - 两个表的sql命令怎么写?

转载 作者:可可西里 更新时间:2023-11-01 07:12:44 24 4
gpt4 key购买 nike

table **salesrule_coupon**: fileds as the following:

coupon_id code

1 Registered_send_5
2 test

表:salesrule_coupon_usage 归档如下:

    coupon_id  customer_id   times_used

1 1 1
1
... 14 ... 1..

现在,我想选择 times_used where the code =Registered_send_5 where customer_id=$id。 sql命令怎么写?谢谢你。

以下是我的,但它不起作用。

$sql = "SELECT times_used FORM salesrule_coupon_usage as a 
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=".'$id.";

当我放

  SELECT times_used FORM salesrule_coupon_usage as a 
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=1

在 phpmyadmin 中。它显示

您的 SQL 语法有误;检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行的“salesrule_coupon_usage as a left join salesrule_coupon as b on a.co”附近使用的正确语法

最佳答案

为什么 $id 中有 '

应该是FROM而不是FORM

关于mysql - 两个表的sql命令怎么写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12456274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com