文章詳情頁
mysql sum去除重復
瀏覽:238日期:2022-06-20 11:32:53
問題描述
A表
id name price1 a 12 b 1
B表
id type1hh1hh2ccselect sum(price) from A as a left join B as b on a.id=b.id where b.type=hh返回結果2,現在我想根據A表id(distinct)統計,得出sum(price)為1的sql語句怎么寫?
問題解答
回答1:B表兩條id為1的記錄,left join查詢會得到兩條記錄并求和,所以就為2了,你在B表中刪除一條id為1的數據,應該就對了。但是問題并沒有解決,可以這樣:
select sum(price) from A as a left join (select id,type from B group by id) as temp on a.id=temp.id where temp.type=hh
由于沒有任何開發環境,沒法測試,大致就這樣吧。
上一條:mysql - Access denied for user ’ODBC’@’localhost’ (using password: NO)下一條:mysql - 如何聯合查詢兩個結構相同的表并且id不重復
相關文章:
1. docker綁定了nginx端口 外部訪問不到2. 前端 - html5 audio不能播放3. javascript - 最近用echarts做統計圖時遇到兩個問題!!4. javascript - 深夜被問題困擾求解惑,rn的API之PermissionsAndroidd的問題5. mysql - 我的myeclipse一直連顯示數據庫連接失敗,不知道為什么6. redis sentinel怎么跑守護進程以及日志記錄位置的?7. android權限被第三方安全軟件禁止,如何獲取該權限狀態8. android - 優酷的安卓及蘋果app還在使用flash技術嗎?9. 利用百度地圖API定位及附件商家信息服務10. nginx - ssl加密訪問證書不受信任
排行榜

網公網安備