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

Cara menggunakan GROUP BY setelah klausa Memiliki Mysql

Anda dapat mencoba menggunakan pilihan luar

SELECT q.*
  FROM
(
  SELECT a.`id` AS aid,ap.`pid`, p.`products_name`, a.accounts_account_number, c.clients_name,a.accounts_product_type AS pptype,
         c.`clients_last_name`, a.`accounts_account_name`,
         (SELECT `status` FROM `bf_account_permissions` WHERE `permission`='Readonly' AND uid=2 AND aid=a.id AND pid=ap.`pid`) AS Readonly,
         (SELECT `status` FROM `bf_account_permissions` WHERE `permission`='Buy' AND uid=2 AND aid=a.id AND pid=ap.`pid`) AS Buy,
         (SELECT `status` FROM `bf_account_permissions` WHERE `permission`='Sell' AND uid=2 AND aid=a.id AND pid=ap.`pid`) AS Sell,
         (SELECT `status` FROM `bf_account_permissions` WHERE `permission`='Disable' AND uid=2 AND aid=a.id AND pid=ap.`pid`) AS `Disable`
    FROM `bf_clients` c INNER JOIN `bf_user_clients` uc ON (c.`id` = uc.`client_id`)
   INNER JOIN `bf_accounts` a ON (c.`id` = a.`accounts_clients`)
   INNER JOIN `bf_account_products` ap ON (a.`id` = ap.`aid`)
   INNER JOIN `bf_products` p ON (ap.`pid` = p.`id`)
   WHERE uc.`agt_user_id`=2 AND a.deleted=0 AND c.deleted=0                
  HAVING (Readonly !='' OR Buy !=''  OR Sell !=''  OR `Disable` !='' ) AND `Disable` !='1'   
) q
 GROUP BY aid


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

  2. Cara memilih catatan berisi MAX(some_field) dalam GROUP(group by)

  3. cara menyesuaikan lebar sel secara otomatis di fpdf menggunakan php dan mysql

  4. Permintaan MySql untuk memilih catatan dengan tanggal tertentu

  5. Apakah INSERT IGNORE mengunci tabel meskipun itu mengabaikan sisipan?