mysql - Sql union 操作
問(wèn)題描述
問(wèn)題:第一種寫(xiě)法:
(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
第二種寫(xiě)法:
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’
為什么第二種寫(xiě)法可以正確執(zhí)行,第一種方式就不可以??
區(qū)別 不是 第一種方式中給 臨時(shí)表起了個(gè)別名嘛,怎么就不行了?高人指點(diǎn)吶
問(wèn)題解答
回答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. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?2. javascript - table列過(guò)多,有什么插件可以提供列排序和選擇顯示列的功能3. showpassword里的this 是什么意思?代表哪個(gè)元素4. javascript - windows下如何使用babel,遇到了困惑5. JavaScript事件6. python - 為什么正常輸出中文沒(méi)有亂碼,zip函數(shù)之后出現(xiàn)中文編程unicode編碼的問(wèn)題,我是遍歷輸出的啊。7. javascript - js中向下取整8. android - 用textview顯示html時(shí)如何寫(xiě)imagegetter獲取網(wǎng)絡(luò)圖片9. 對(duì)mysql某個(gè)字段監(jiān)控的功能10. html - vue項(xiàng)目中用到了elementUI問(wèn)題
