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

Bantuan kueri sql Magento diperlukan dengan kueri besar-besaran

kami sedang melakukan beberapa laporan serupa. Yang perlu Anda lakukan:

  • Mulai dari produk sederhana
  • JOIN melalui tabel catalog_product_super_link pada produk yang dapat dikonfigurasi
  • Di bagian SELECT dari kueri, gunakan IF => jika nilai produk sederhana ada, gunakan, jika tidak gunakan nilai produk yang dapat dikonfigurasi (atau sebaliknya)

Contoh

SELECT
    o.increment_id,    
    oi.order_id,
    o.STATUS AS order_status,
    o.created_at,                  
    ROUND(SUM(IF(oi2.qty_ordered IS NOT NULL, IF(oi2.qty_ordered > oi.qty_ordered, oi2.qty_ordered, oi.qty_ordered), oi.qty_ordered)), 0) AS cqty_ordered,
    ROUND(SUM(IF(oi2.qty_canceled IS NOT NULL, IF(oi2.qty_canceled > oi.qty_canceled, oi2.qty_canceled, oi.qty_canceled), oi.qty_canceled)), 0) AS cqty_canceled,
    ROUND(SUM(IF(oi2.qty_shipped IS NOT NULL, IF(oi2.qty_shipped > oi.qty_shipped, oi2.qty_shipped, oi.qty_shipped), oi.qty_shipped)), 0) AS cqty_shipped,
    ROUND(SUM(IF(oi2.qty_ordered IS NOT NULL, IF(oi2.qty_ordered > oi.qty_ordered, oi2.qty_ordered, oi.qty_ordered), oi.qty_ordered)) - SUM(IF(oi2.qty_canceled IS NOT NULL, IF(oi2.qty_canceled > oi.qty_canceled, oi2.qty_canceled, oi.qty_canceled), oi.qty_canceled)) - SUM(IF(oi2.qty_shipped IS NOT NULL, IF(oi2.qty_shipped > oi.qty_shipped, oi2.qty_shipped, oi.qty_shipped), oi.qty_shipped)), 0) AS cqty_missing
FROM sales_flat_order_item AS oi
INNER JOIN sales_flat_order AS o ON oi.order_id=o.entity_id
LEFT JOIN sales_flat_order_item AS oi2 ON oi.parent_item_id=oi2.item_id AND oi2.product_type='configurable'
WHERE oi.product_type='simple'
GROUP BY oi.order_id
HAVING cqty_missing=0 AND order_status NOT IN ('complete','canceled','closed');



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Praktik terbaik untuk menyimpan tag dalam database?

  2. permintaan kompleks integrasi sql teman bersama

  3. PDO-MySQL:Nilai Boolean dikonversi menjadi 1 atau string kosong pada pengikatan pernyataan yang disiapkan

  4. Atur posting forum berdasarkan waktu balasan terbaru

  5. mysql - kueri tiga tabel