


How to use MySQL to create a user points record table for the grocery shopping system
The vegetable shopping system is a very practical application. It can easily provide users with fresh vegetables, fruits and other ingredients. In order to better serve users, user points need to be established Record form to track users’ consumption behavior and usage habits. This article will introduce how to use MySQL to create a user points record table for the grocery shopping system, and provide specific code examples.
1. Design of user points record table
The user points record table is a table used to record changes in user points. As users use the grocery shopping system to shop and consume, user points also increase. Corresponding changes will occur. Therefore, the following factors need to be considered when establishing a user points record table:
1. User information
2. Points change type (consumption, refund, activity, etc.)
3. Points change amount
4. Change time
Based on the above considerations, we can design the following user points record table:
Field name | Data type | Description |
---|---|---|
int(11) | Auto-increment primary key | |
int(11) | userID | |
varchar(20 ) | Points change type (consumption, refund, activity, etc.) | |
int(11) | Change amount | |
datetime | Change time (format: YYYY-MM-DD HH:MM:SS) |
CREATE TABLE user_points ( id int(11) NOT NULL AUTO_INCREMENT, user_id int(11) NOT NULL COMMENT '用户ID', change_type varchar(20) NOT NULL COMMENT '积分变化类型(消费、退款、活动等)', change_amount int(11) NOT NULL COMMENT '积分变化额度', change_time datetime NOT NULL COMMENT '变化时间(格式:YYYY-MM-DD HH:MM:SS)', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户积分记录表';
INSERT INTO user_points (user_id, change_type, change_amount, change_time) VALUES (10001, '消费', -100, '2021-06-01 12:00:00'), (10001, '消费', -50, '2021-06-03 18:00:00'), (10001, '活动', 200, '2021-06-05 09:00:00'), (10002, '消费', -80, '2021-06-02 15:00:00'), (10002, '消费', -120, '2021-06-04 20:00:00'), (10002, '活动', 150, '2021-06-06 13:00:00');
SELECT SUM(change_amount) AS point_total FROM user_points WHERE user_id=10001;
SELECT * FROM user_points WHERE user_id=10001 ORDER BY change_time DESC LIMIT 5;
SELECT * FROM user_points WHERE change_time BETWEEN '2021-06-01 00:00:00' AND '2021-06-30 23:59:59';
The above is the detailed content of How to use MySQL to create a user points record table for the grocery shopping system. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

Pinduoduo software provides a lot of good products, you can buy them anytime and anywhere, and the quality of each product is strictly controlled, every product is genuine, and there are many preferential shopping discounts, allowing everyone to shop online Simply can not stop. Enter your mobile phone number to log in online, add multiple delivery addresses and contact information online, and check the latest logistics trends at any time. Product sections of different categories are open, search and swipe up and down to purchase and place orders, and experience convenience without leaving home. With the online shopping service, you can also view all purchase records, including the goods you have purchased, and receive dozens of shopping red envelopes and coupons for free. Now the editor has provided Pinduoduo users with a detailed online way to view purchased product records. method. 1. Open your phone and click on the Pinduoduo icon.

Certain folders are not always accessible due to permissions, and in today’s guide we will show you how to access user folders on your old hard drive on Windows 11. The process is simple but can take a while, sometimes even hours, depending on the size of the drive, so be extra patient and follow the instructions in this guide closely. Why can't I access my user folders on my old hard drive? User folders are owned by another computer, so you cannot modify them. You don't have any permissions on the folder other than ownership. How to open user files on old hard drive? 1. Take ownership of the folder and change permissions Find the old user directory, right-click on it and select Properties. Navigate to "An

Many users have been added to the Ubuntu system. I want to delete the users that are no longer in use. How to delete them? Let’s take a look at the detailed tutorial below. 1. Open the terminal command line and use the userdel command to delete the specified user. Be sure to add the sudo permission command, as shown in the figure below. 2. When deleting, be sure to be in the administrator directory. Ordinary users do not have this permission. , as shown in the figure below 3. After the delete command is executed, how to judge whether it has been truly deleted? Next we use the cat command to open the passwd file, as shown in the figure below 4. We see that the deleted user information is no longer in the passwd file, which proves that the user has been deleted, as shown in the figure below 5. Then we enter the home file

Microsoft began rolling out KB2 to the public as an optional update for Windows 503145511H22 or later. This is the first update to enable Windows 11 Moment 4 features by default, including Windows Copilot in supported areas, preview support for items in the Start menu, ungrouping of the taskbar, and more. Additionally, it fixes several Windows 11 bugs, including potential performance issues that caused memory leaks. But ironically, the optional update for September 2023 will be a disaster for users trying to install the update, or even for those who have already installed it. Many users will not install this Wi

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L
