distinct 多列问题结合group by的解决方法
时间:2024-01-21 11:18:23
表 table1
id RegName PostionSN PersonSN
1 山东齐鲁制药 223 2
2 山东齐鲁制药 224 2
3 北京城建公司 225 2
4 科技公司 225 2
我想获得结果是
id RegName PostionSN PersonSN
1 山东齐鲁制药 223 2
3 北京城建公司 225 2
4 科技公司 225 2
select distinct RegName,PostionSN,PersonSN from table1
如果查询的是多列 distinct 用和不用一样
只能用group by
用group by RegName
select * from table1 where id in (select min(id) from table1 group by RegName) and PersonSN=2
标签:distinct,group,by
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server误区30日谈 第3天 即时文件初始化特性可以在SQL Server中开启和关闭
2024-01-16 18:38:28
![](https://img.aspxhome.com/file/2023/3/124473_0s.png)
Python中BeautifulSoup通过查找Id获取元素信息
2022-12-22 22:08:59
![](https://img.aspxhome.com/file/2023/1/110241_0s.png)
python 三元运算符使用解析
2021-05-02 17:03:28
用css+Javascript实现扫描线效果图片
2007-11-08 19:12:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113824691s.jpg)
Opencv python 图片生成视频的方法示例
2021-11-08 22:18:38
![](https://img.aspxhome.com/file/2023/1/102791_0s.jpg)
Python+SimpleRNN实现股票预测详解
2022-12-04 13:08:26
![](https://img.aspxhome.com/file/2023/8/105778_0s.png)
IDEA最新激活码永久激活教程附激活失败原因汇总
2023-12-13 11:57:29
![](https://img.aspxhome.com/file/2023/5/131895_0s.png)
深入理解javascript中defer的作用
2024-04-16 10:32:55
Python3 实现随机生成一组不重复数并按行写入文件
2021-11-25 18:05:35
pandas行和列的获取的实现
2022-06-05 07:57:49
python字典get()方法用法分析
2023-04-01 23:50:41
Python中seaborn库之countplot的数据可视化使用
2023-08-10 20:38:56
![](https://img.aspxhome.com/file/2023/6/62026_0s.png)
聊聊Golang的语言结构和变量问题
2024-04-29 13:05:00
![](https://img.aspxhome.com/file/2023/8/133928_0s.png)
Python漏洞验证程序Poc利用入门到实战编写
2022-05-08 00:00:31
![](https://img.aspxhome.com/file/2023/3/110073_0s.jpg)
详解python函数的闭包问题(内部函数与外部函数详述)
2023-01-22 20:53:01
Python中使用Counter进行字典创建以及key数量统计的方法
2023-10-05 20:16:36
asp如何读取注册表的信息?
2009-11-19 21:18:00
pycharm不以pytest方式运行,想要切换回普通模式运行的操作
2022-02-05 15:27:10
![](https://img.aspxhome.com/file/2023/7/104817_0s.jpg)
最常用的12种设计模式小结
2024-04-29 13:17:45
mysql重复索引与冗余索引实例分析
2024-01-25 11:52:53
![](https://img.aspxhome.com/file/2023/4/101124_0s.jpg)