mysql - Sql union 操作
问题描述
问题:第一种写法:
(select du.day,du.apptoken ,du.version, du.channel,du.city,du.count,concat(apptoken, version,channel,city) as joinkey from day_new_users_count du where day=’20170319’) as dayUsers union (select tu.day,tu.apptoken,tu.version,tu.channel,tu.city,tu.count,concat(apptoken,version,channel,city) as joinkey from total_users tu where day=’20170318’) as toUsers
第二种写法:
select du.day,du.apptoken ,du.version, du.channel,du.city,du.count,concat(apptoken, version,channel,city) as joinkey from day_new_users_count du where day=’20170319’ union select tu.day,tu.apptoken,tu.version,tu.channel,tu.city,tu.count,concat(apptoken,version,channel,city) as joinkey from total_users tu where day=’20170318’
为什么第二种写法可以正确执行,第一种方式就不可以??
区别 不是 第一种方式中给 临时表起了个别名嘛,怎么就不行了?高人指点呐
问题解答
回答1:select * from (selectdu.day, du.apptoken , du.version, du.channel, du.city, du.count,concat(apptoken, version,channel,city) as joinkeyfrom day_new_users_count duwhere day=’20170319’) as dayUsersunionselect * from (selecttu.day, tu.apptoken, tu.version, tu.channel, tu.city, tu.count,concat(apptoken,version,channel,city) as joinkeyfrom total_users tuwhere day=’20170318’) as toUsers
相关文章:
1. javascript - js输入框限定字数问题2. 个人主页博客统计中的“进入博客”不能点击3. css3 - 微信前端页面遇到的transition过渡动画的bug4. Browser-sync安装失败问题5. php - 微信开发验证服务器有效性6. python如何设置一个随着系统时间变化的动态变量?7. javascript - Ajax返回json格式之后的数据解析后取出来的数据为undefined?8. javascript - jquery选择的dom元素如何更新?9. 网页爬虫 - 关于Python的编码与解码问题10. javascript - Webapp 关闭后重新打开无需登录如何操作?

网公网安备