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. javascript - webpack熱加載配置不生效2. css3 - 這個右下角折角用css怎么畫出來?3. debian - docker依賴的aufs-tools源碼哪里可以找到啊?4. mysql - eclispe無法打開數據庫連接5. windows2003下的apache響應時間特別長?6. javascript - 在 model里定義的 引用表模型時,model為undefined。7. 關于Java引用傳遞的一個困惑?8. java - 根據月份查詢多個表里的內容怎么實現好?9. javascript - 一個關于客戶端和前端通信的疑惑?10. php - 一個操作請求多個服務如何保證數據的安全?
