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. java - 判斷數(shù)據(jù)在數(shù)據(jù)庫(kù)中是否已存在.2. android百度地圖定位問(wèn)題3. javascript - JS new Date() 保存到 mongodb 中會(huì)早8個(gè)小時(shí),我們這里是東八區(qū),mongodb 保存的是格林尼治時(shí)間4. python - django models 為生成的html元素添加樣式。5. javascript - 關(guān)于圣杯布局的一點(diǎn)疑惑6. android - 圖片列表分組之后復(fù)用問(wèn)題7. css - input間的間距和文字上下居中8. nginx bind failed9. 為什么我寫(xiě)的PHP不行10. android - 有數(shù)據(jù)要處理的時(shí)候如何使用rxJava進(jìn)行異步處理數(shù)據(jù)

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