Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

jumlah harga anak di tabel lain mysql

Coba ini;)

select ancestor_id as userid, sum(b.price) as total
from webineh_prefix_nodes_paths_tmp a 
join webineh_prefix_nodes_tmp b 
on b.userid = a.descendant_id
where a.ancestor_id in (select userid from webineh_prefix_nodes_tmp where parent = 1)
group by ancestor_id

Demo SQLFiddle

Diedit

select ancestor_id as userid, sum(b.price) as total
from webineh_prefix_nodes_paths_tmp a 
join webineh_prefix_nodes_tmp b 
on b.userid = a.descendant_id
inner join webineh_prefix_nodes_tmp c
on a.ancestor_id = c.userid
and c.parent = 1
group by ancestor_id

Demo SQLFiddle



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Kesalahan fatal Wordpress:Kesalahan Tidak Tertangkap:Panggilan ke fungsi yang tidak ditentukan mysql_connect() di /wp-includes/wp-db.php:1570

  2. Ambil data MySQL menggunakan klausa where

  3. Menyiarkan data tabel database MySQL waktu nyata

  4. Binding C++ untuk MySQL

  5. Python kehilangan koneksi ke database MySQL setelah sekitar satu hari