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. macos - mac下docker如何設(shè)置代理2. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數(shù)賦值輸錯誤是什么原因?3. MySQL數(shù)據(jù)庫中文亂碼的原因4. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””5. docker不顯示端口映射呢?6. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?7. android studio總是在processes running好久8. angular.js - 關(guān)于$apply()9. docker-compose 為何找不到配置文件?10. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下
