当前位置:网站首页>Problem recording and thinking
Problem recording and thinking
2022-06-25 23:20:00 【newProxyInstance】
Preface : Daily problem recording and thinking .
Mysql Group by sentence
Study group by The first thing to know is What are aggregate functions ? What are the aggregation functions ?
Most common usage , Check the minimum specifications for each product .
SELECT
goods_id,
min( goods_price )
FROM
tb_sku_info
GROUP BY
goods_id
But we may need other fields such as id perhaps name wait , An error may be reported when querying non aggregated columns , For example, the following statement .
SELECT
id,
goods_id,
min( goods_price )
FROM
tb_sku_info
GROUP BY
goods_id
Inquire about sql_mode sentence
select @@sql_mode
set @@sql_mode = ONLY_FULL_GROUP_BY
select * from config_info group by group_id
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
'nacos_config.config_info.id' which is not functionally dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
Remove sql_mode in ONLY_FULL_GROUP_BY This specification is incorrect , If you don't pay attention, it will cause other problems .
The most obvious is Wrong line problem .
SELECT
id,
specifications,
goods_id,
min( goods_price )
FROM
tb_sku_info
GROUP BY
goods_id
The query results are shown in the figure

After querying the general table, you can see that the price in the red box is the lowest price of goods .

Correct writing , Query through a link , use The lowest price is id Two Field to uniquely match row records in the main table .
SELECT
*
FROM
tb_sku_info AS t1
INNER JOIN ( SELECT goods_id, min( goods_price ) AS mixPrice FROM tb_sku_info GROUP BY goods_id ) AS t2 ON t1.goods_id = t2.goods_id
AND t1.goods_price = t2.mixPrice

边栏推荐
- C language and the creation and use of database
- Trillions of hot money smashed into the space economy. Is it really a good business?
- Unity技术手册 - 粒子基础主模块属性-上
- What aspects should we start with in the feasibility analysis of dry goods?
- Eureka core ⼼ source code analysis
- Circuit module analysis exercise 5 (power supply)
- What is CDN acceleration
- The Ping class of unity uses
- ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数
- 判断预约时间是否已经过期
猜你喜欢

Ribbon core ⼼ source code analysis

How to use JMeter for interface testing

Unity的Ping類使用

ES6-- 模板字符串、对象的简化写法、箭头函数

Pit resolution encountered using East OCR (compile LAMS)

Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant

ES6 --- 数值扩展、对象拓展

Civil Aviation Administration: by 2025, China will initially build a safe, intelligent, efficient and green aviation logistics system

哪些PHP开源作品值得关注

Basic concepts of processor scheduling
随机推荐
What do l and R of earphone mean?
建立自己的网站(15)
. SQL database import error: / *! 40101 SET @OLD_ COLLATION_ [email protected]@COLLATION_ CONNECTION */
Fastjson反序列化随机性失败
牛客小白月赛52--E 分组求对数和(二分)
Multi modal data can also be Mae? Berkeley & Google proposed m3ae to conduct Mae on image and text data! The optimal masking rate can reach 75%, significantly higher than 15% of Bert
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
zabbix_ Server configuration file details
[modulebuilder] GP service realizes the intersection selection of two layers in SDE
Paper notes: multi tag learning MSWl
Thinking while walking
Equivalence class, boundary value, application method and application scenario of scenario method
As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)
2. What is the geometric meaning of a vector multiplying its transpose?
Unity technical manual - getKey and getaxis and getbutton
Why can't the mobile phone be used and the computer be connected
LM小型可编程控制器软件(基于CoDeSys)笔记十七:pto脉冲功能块
pdm的皮毛
LM small programmable controller software (based on CoDeSys) note XVII: PTO pulse function block
字符串变形(字符串大小写切换和变现)