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. python中merge后文件莫名变得非常大2. 小程序怎么加外链,语句怎么写!求救新手,开文档没发现3. java - MySQL显示中文星期4. vue打包和PHP后台怎样同域名部署配置5. python - matplotlib 做一个饼状图出错6. python - 字符串中反斜杠的替换7. python - <flask web 开发>项目permission问题8. javascript - 给页面加了动画,在微信浏览器中显示混乱,急救9. base64_decode调用出错windows server 2008R2系统上出现的10. MySQL 联合查询并更新到另一个表,求教
