mysql 的 union 与group by 问题
selectcount(*)asN,a,bfrom(selecta,bfrom表1unionselecta,bfrom表2)groupbyaorderbyN为什么在用ac...
select count(*) as N,a,b from (select a,b from 表1 union select a,b from 表2) group by a order by N
为什么在用access数据库就好使 用mysql 就不行呢 在mysql下该怎么写 请教各位大师 展开
为什么在用access数据库就好使 用mysql 就不行呢 在mysql下该怎么写 请教各位大师 展开
2个回答
展开全部
会不会是 group by 的地方 少了一个 字段 b
mysql> select
-> count(*) as N,
-> a,
-> b
-> from
-> (select
-> 1 AS a,
-> 1 AS b
-> union
-> select
-> 2 AS a,
-> 2 AS b
-> ) as tmp
-> group by a, b
-> order by N
-> ;
+---+---+---+
| N | a | b |
+---+---+---+
| 1 | 1 | 1 |
| 1 | 2 | 2 |
+---+---+---+
2 rows in set (0.00 sec)
mysql> select
-> count(*) as N,
-> a,
-> b
-> from
-> (select
-> 1 AS a,
-> 1 AS b
-> union
-> select
-> 2 AS a,
-> 2 AS b
-> ) as tmp
-> group by a, b
-> order by N
-> ;
+---+---+---+
| N | a | b |
+---+---+---+
| 1 | 1 | 1 |
| 1 | 2 | 2 |
+---+---+---+
2 rows in set (0.00 sec)
追问
谢谢您的答案 是参考你的答案 完成的 呵呵
sql_1="select a,b from 表1"
sql_2="select a,b from 表2"
sql_3=sql_1 &" union all "& sql_2
sql_4="select count(*) as N,a,b from ("& sql_3 &" as NewName) NewName group by author order by NewSum desc"
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询