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. 前端 - ng-view不能加载进模板2. Android下,rxJava+retrofit 并发上传文件和串行上传文件的效率为什么差不多?3. javascript - 如何做出pc网站随鼠标滚动动态出现效果4. java后台怎么转换ios传过来的utf-8的json数据5. docker-compose 为何找不到配置文件?6. javascript - angularjs怎么获取repeat里的某些$index值?7. javascript - [MUI 子webview定位]8. html5 - 使用angular中,图片上传功能中选择多张图片是怎么实现的?有什么好的思路吗?9. html5和Flash对抗是什么情况?10. android-studio - android studio 结巴了,有什么办法可以治好它吗?
