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 - 微信小程序 如何实现这种左滑动出现删除的办法?有相关api吗?2. web服务器 - ubuntu下布置apache加wsgi加python3. tp6 事务闭包操作问题4. 主从复制 - MySQL 主从延迟 300s 以上,求大神解答5. python打开.py文件的时候出现window无法打开该文件是怎么回事呢?6. javascript - sublime快键键问题7. css - 图片的宽度发生变化而高度却没有相应变?8. docker 17.03 怎么配置 registry mirror ?9. dockerfile - 为什么docker容器启动不了?10. docker gitlab 如何git clone?

网公网安备