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. css - 关于input标签disabled问题2. html5 - 百度Ueditor代码高亮和代码段滚动条冲突是怎么回事?3. javascript - 关于一段 for 循环代码执行顺序的问题4. docker api 开发的端口怎么获取?5. debian - docker依赖的aufs-tools源码哪里可以找到啊?6. javascript - 静态页面引公共头尾文件,js怎么写吖?7. javascript - vue 数据更新了。但是dom没有更新,,,,,如图8. java - 为什么要将Runnable接口的子类对象传递给Thread的构造函数?9. java基础,求解答。10. 如何调整IDEA中直接运行java程序的日志输出级别?