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. node.js - nodejs+express+vue2. 使用mysql命令行連接遠程數(shù)據(jù)庫host跳轉(zhuǎn)3. python - 如何把152753這個字符串轉(zhuǎn)變成時間格式15:27:534. javascript - onclick事件點擊不起作用5. java - web端百度網(wǎng)盤的一個操作為什么要分兩次請求服務(wù)器, 有什么好處嗎6. DADB.class.php文件的代碼怎么寫7. python 字符串匹配問題8. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。9. javascript - 如何獲取未來元素的父元素在頁面中所有相同元素中是第幾個?10. python對8000行csv添加列

網(wǎng)公網(wǎng)安備