Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Dapatkan jumlah nilai kolom tertentu di Oracle dengan gabungan dalam

Coba ini

SELECT T.*,S.* FROM
(
  Select TD.category_name,TD.branch_name,TM.created_date,TM.user_id,TD.order_details_id,TD.branch_id
  From tbl_orderdetails TD Inner Join tbl_ordermaster TM ON 
    TD.order_master_id = TM.ordermasterid 
  Where TM.user_id='12'
) T Left Join
(
  Select T1.branch_name,Count(T1.branch_name) As No_Of_Branch
  From tbl_orderdetails T1 Inner Join tbl_ordermaster T2 ON 
       T1.order_master_id = T2.ordermasterid 
  Where T2.user_id='12'
  Group By T1.branch_name
) S On S.branch_name = T.branch_name

Perbarui

Jika Anda ingin mendapatkan Max dari count

Coba ini

SELECT T.*,S.* FROM
(
  Select TD.category_name,TD.branch_name,TM.created_date,TM.user_id,TD.order_details_id,TD.branch_id
  From tbl_orderdetails TD Inner Join tbl_ordermaster TM ON 
    TD.order_master_id = TM.ordermasterid 
  Where TM.user_id='12'
) T Inner Join
(
SELECT M.branch_name,Max(M.No_Of_Branch) FROM
  (
    Select T1.branch_name,Count(T1.branch_name) As No_Of_Branch
    From tbl_orderdetails T1 Inner Join tbl_ordermaster T2 ON 
         T1.order_master_id = T2.ordermasterid 
    Where T2.user_id='12'
    Group By T1.branch_name
  ) M Group By M.branch_name
) S On S.branch_name = T.branch_name


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. isi kolom berdasarkan 2 kolom

  2. Opsi Pemformatan SQLcl (Oracle)

  3. Memperbarui Tampilan Gabung tanpa mendapatkan Kesalahan Tanpa Kunci yang Diawetkan

  4. RU atau RU?

  5. Cara menggunakan oracle di cakePHP