当前位置:网站首页>Classic sql example
Classic sql example
2022-08-06 03:32:00 【programming little white】
1. Find all the units and corresponding barcodes of the products in the order, and combine them for output:
group_concat([DISTINCT] Field to concatenate [Order BY ASC/DESC sort field] [Separator
'separator'])
Goods table tp_goods:
Goods unit table tp_goodsunit:
Order form tp_order:
SELECT o.orderNo,o.number,o.goodsUnit,GROUP_CONCAT(DISTINCT CONCAT(gu.unit,gu.barcode) SEPARATOR '*') AS allBarcodeFROM tp_order oLEFT JOIN tp_goodsunit gu ON gu.goodsId=o.goodsIdWHERE o.id = 1GROUP BY o.orderNo,o.number,o.goodsUnit
2. According to the product unit of the order, find the corresponding barcode:
Goods table tp_goods:
Goods unit table tp_goodsunit:
Order form tp_order:
SELECT o.orderNo,o.number,o.goodsUnit,u.barcodeFROM tp_order oLEFT JOIN(SELECT gu.barcode,gu.goodsIdFROM tp_goodsunit guINNER JOIN tp_order poON gu.goodsId=po.goodsId AND gu.unit=po.goodsUnit AND po.id=1) u ON u.goodsId = o.goodsIdWHERE o.id = 1
3.sql to determine whether a field is a null value, or an empty string
LENGTH(u.barcode)>0, means not null, not empty string
LENGTH(u.barcode)<=0, means null or empty string
IF(LENGTH(u.barcode)>0,u.barcode,g.barcode) AS a //u.barcode is not null and not empty string, take u.barcode, otherwise take g.barcode边栏推荐
- django报错 ModuleNotFoundError: No module named 'mysqlclient'
- firewall and ufw notes
- The second day of learning MySQL: SQL (basic)
- 离散数学期末习题
- 请求DNS查找的host命令示例
- 走!VR技术带你沉浸式看展
- sql server , 两个表,相同字段,相同数据量(5000万), 执行相同的查询,一个表执行的是索引扫描,扫描5000万,耗时2分钟, 另一个表执行的是索引查找,只查找10万,耗时1秒。为什么会有这么大的差别?
- leetcode 15. Sum of three numbers
- 全同态加密知识体系整理
- Mysql安装 求大拿解答
猜你喜欢

个推数据智能技术实践 | 教你打造数据质量心电图,智能检测数据“心跳”异常

喜欢我们不如加入我们:来投稿吧,稿酬靠谱!

电赛的控制类选题之问

Single player up to 50,000 bonus!The top conference paper recurrence competition is officially launched, and 70+ public tasks are waiting for you to challenge

Introduction to Elliptic Curves (4): Elliptic Curve Security, Compared with RSA

物联网协议概述

经典sql例子

2022年阿里云服务器配置选取攻略

ctf (finalrec)

2018HBCPC部分题解
随机推荐
Liunx常用命令
Single player up to 50,000 bonus!The top conference paper recurrence competition is officially launched, and 70+ public tasks are waiting for you to challenge
慎用BeanUtils,性能真的拉跨!
ctf (finalrec)
Fragment的四种跳转方式
谷歌分析中的转化目标设置后,大概多久能显示在Google adwords后台?
文献阅读---普通狗牙根阳江基因组单倍型解析与基因组稳定性和匍匐性研究
智能合约安全——随机数
R语言ggplot2循环中保存图片失败问题
Sring中常用注解归纳
经典sql例子
leetcode 17. Letter Combinations of Phone Numbers
Why is NPDP becoming more and more popular?product manager, do you know?
分享好用无广告的手机浏览器,亲测值得下载
【Translation】Serverless Architecture: Pros and Cons
Lvm root partition expansion
Literature Reading---Analysis of Genome Haplotypes and Genome Stability and Creeping of Common Bermudagrass Yangjiang
Crypto Bear Market Offers M&A Opportunity Ambitious or Savior?The only truth is that interests come first
造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
leetcode 15. Sum of three numbers