有三个表 第一个表是产品表(goods):
<code>字段:id,goods_id,.... </code>
第二个表是订单-商品表(order):
<code>字段:id,goods_id,order_id,.... </code>
第三个表是订单详情表(order_info):
<code>字段:id,order_id,pay_time,... </code>
产品表 和 订单-商品表 是一对多的关系
订单-商品表 和 订单详情表 是一对一的关系
订单-商品表没有订单完成的状态,但是可以根据 订单详情表 的pay_time(支付时间)判断是否完成订单
现在要实现的是根据提供的时间检测出产品表,上架后时间之内不动销的产品?
补充:现在已经完成goods表关联order表查询获得没有订单的产品ID了,但是需要关联第三个表,还需要加上时间筛选,感觉之前的办法很难实现。
回复内容:
有三个表 第一个表是产品表(goods):
<code>字段:id,goods_id,.... </code>
第二个表是订单-商品表(order):
<code>字段:id,goods_id,order_id,.... </code>
第三个表是订单详情表(order_info):
<code>字段:id,order_id,pay_time,... </code>
产品表 和 订单-商品表 是一对多的关系
订单-商品表 和 订单详情表 是一对一的关系
订单-商品表没有订单完成的状态,但是可以根据 订单详情表 的pay_time(支付时间)判断是否完成订单
现在要实现的是根据提供的时间检测出产品表,上架后时间之内不动销的产品?
补充:现在已经完成goods表关联order表查询获得没有订单的产品ID了,但是需要关联第三个表,还需要加上时间筛选,感觉之前的办法很难实现。
分析一下问题,个人窃以为难以实现的关键:
- 不动销的概念不清晰。不知道是题主描述的不够清晰,还是题主本来对需求理解的不够清晰。不动销是指某个商品根本就没有订单,还是指支付成功笔数在多少数量之内呢?
- 订单表设计的不合理。从题主的描述来看,这是一个很明显的交易系统,涉及商品、订单、支付3个环节,后续还可能还涉及到题主未提及的发货、结算、退款和对账等环节。订单作为交易系统的核心环节,题主给出的表结构很显然没法体现一个交易流程当前处在哪个环节,即缺少订单的状态。这就造成很难判断订单的统计标准。
- 由于第2点的问题导致关联的商品分析也比较困难。题主给出的根据支付时间判断订单完成与否,是存在一定问题:首先,交易系统的时间一般只是作为日志信息记录,一个订单是否完成或处在哪个阶段是不能也不应该由时间确定,而应该有一个确定明确的标志;其次,系统的时间往往受很多因素影响,它不是一个精确值,对于分布式系统,其精确度更差,这样在一定程度上对以时间为统计依据的结果必然会带来影响。
综上几点,个人觉得题主应该在订单表(order),增加状态列(status)信息,这样的话就很好统计了。例如status=1表示订单完成,则SQL如下:
<code>1. 交易订单少于指定笔数为不动销 select goods_id from ( select goods_id, count(1) as num from order where status = 1 group by goods_id) t where t.num </code>

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

In PHP, trait is suitable for situations where method reuse is required but not suitable for inheritance. 1) Trait allows multiplexing methods in classes to avoid multiple inheritance complexity. 2) When using trait, you need to pay attention to method conflicts, which can be resolved through the alternative and as keywords. 3) Overuse of trait should be avoided and its single responsibility should be maintained to optimize performance and improve code maintainability.

Dependency Injection Container (DIC) is a tool that manages and provides object dependencies for use in PHP projects. The main benefits of DIC include: 1. Decoupling, making components independent, and the code is easy to maintain and test; 2. Flexibility, easy to replace or modify dependencies; 3. Testability, convenient for injecting mock objects for unit testing.

SplFixedArray is a fixed-size array in PHP, suitable for scenarios where high performance and low memory usage are required. 1) It needs to specify the size when creating to avoid the overhead caused by dynamic adjustment. 2) Based on C language array, directly operates memory and fast access speed. 3) Suitable for large-scale data processing and memory-sensitive environments, but it needs to be used with caution because its size is fixed.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In JavaScript, you can use NullCoalescingOperator(??) and NullCoalescingAssignmentOperator(??=). 1.??Returns the first non-null or non-undefined operand. 2.??= Assign the variable to the value of the right operand, but only if the variable is null or undefined. These operators simplify code logic, improve readability and performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use