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’
為什么第二種寫法可以正確執(zhí)行,第一種方式就不可以??
區(qū)別 不是 第一種方式中給 臨時表起了個別名嘛,怎么就不行了?高人指點吶
問題解答
回答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
相關(guān)文章:
1. docker鏡像push報錯2. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題3. docker-compose中volumes的問題4. angular.js - angular內(nèi)容過長展開收起效果5. dockerfile - 為什么docker容器啟動不了?6. 關(guān)docker hub上有些鏡像的tag被標記““This image has vulnerabilities””7. debian - docker依賴的aufs-tools源碼哪里可以找到啊?8. golang - 用IDE看docker源碼時的小問題9. docker api 開發(fā)的端口怎么獲取?10. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗!
