How to assign default values ​​to fields when querying MySQL

How to assign default values ​​to fields when querying MySQL

need

When querying a field, you need to give the same value to a field.

You can hard-code this value or get it from the database

1. Hard-coded values

SELECT
 mfr_id AS mfrId,
 mfr_name AS mfrName,
 IFNULL(NULL, 587694978080178176) AS suppId
FROM
 mater_prod materProd

Query results

2. Get values ​​from the database

SELECT
 mfr_id AS mfrId,
 mfr_name AS mfrName,
 IFNULL(NULL, mfr_id) AS suppId
FROM
 mater_prod materProd

Query results

Supplementary knowledge: How to set a default value if the mysql query field is empty

In common cases, the following is to calculate inventory. If the inventory or locked inventory is empty, the default value is 0.

SELECT
(IFNULL(t_inventory.pro_number,0)-IFNULL(t_inventory.locked_number,0)) AS content_number
FROM
t_inventory

The above operation of assigning default values ​​to fields during MySQL query is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL implementation of extracting and querying JSON type field data
  • MySQL retrieves data based on the JSON field content as a query condition (including JSON arrays)
  • Mybatis mysql fuzzy query method (CONCAT multiple fields) and bug
  • Sample code for implementing string split function in MySQL query field
  • Detailed explanation of querying JSON format fields in MySQL
  • Querying MySQL date and time fields

<<:  Vue realizes the product magnifying glass effect

>>:  How to install rabbitmq-server using yum on centos

Recommend

js to achieve a simple magnifying glass effect

This article shares the specific code of js to ac...

How to use CSS to display multiple images horizontally in the center

Let me first talk about the implementation steps:...

Share 12 commonly used Loaders in Webpack (Summary)

Table of contents Preface style-loader css-loader...

JS array deduplication details

Table of contents 1 Test Cases 2 JS array dedupli...

Detailed explanation of the new CSS display:box property

1. display:box; Setting this property on an eleme...

Example of fork and mutex lock process in Linux multithreading

Table of contents Question: 1. First attempt 2. R...

Element sample code to implement dynamic table

Table of contents 【Code background】 【Code Impleme...

Detailed explanation of Vue custom instructions and their use

Table of contents 1. What is a directive? Some co...

Detailed explanation of incompatible changes in rendering functions in Vue3

Table of contents Rendering API changes Render fu...

CSS3 gradient background compatibility issues

When we make a gradient background color, we will...

Vue implements a small weather forecast application

This is a website I imitated when I was self-stud...

Display flex arrangement in CSS (layout tool)

Regarding display: flex layout, some people have ...