admin管理员组

文章数量:1430609

I need do join 2 tables of booking in WordPress,

 $wpdb->get_results("SELECT * FROM $db",ARRAY_A);

For example :

SELECT
  b.*, 
  GROUP_CONCAT(ba.NamePack SEPARATOR "<br />") Extras,
  (SUM(ba.Price)+b.Price) AS Total 
FROM 
  wp_booking b 
LEFT JOIN wp_booking_additionals ba ON b.Id_Booking = ba.Fk_IdBooking 
GROUP BY Id_Booking

I need do join 2 tables of booking in WordPress,

 $wpdb->get_results("SELECT * FROM $db",ARRAY_A);

For example :

SELECT
  b.*, 
  GROUP_CONCAT(ba.NamePack SEPARATOR "<br />") Extras,
  (SUM(ba.Price)+b.Price) AS Total 
FROM 
  wp_booking b 
LEFT JOIN wp_booking_additionals ba ON b.Id_Booking = ba.Fk_IdBooking 
GROUP BY Id_Booking
Share Improve this question edited Apr 24, 2019 at 9:09 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Mar 30, 2019 at 3:54 Carlos Ramírez FloresCarlos Ramírez Flores 1
Add a comment  | 

1 Answer 1

Reset to default 0

I have one solution

global $wpdb;
$db= $wpdb->prefix.'booking';
$dbAdditonal= $wpdb->prefix.'booking_additionals';
$booking = $wpdb->get_results("
  SELECT b.*,  
    IFNULL(GROUP_CONCAT(ba.NamePack SEPARATOR '<br />'),'N/A') Extras,
    FORMAT(IFNULL(SUM(ba.Price),0)+IFNULL(b.Price,0),2) AS Total
  FROM
    $db b
  LEFT JOIN $dbAdditonal ba ON b.Id_Booking = ba.Fk_IdBooking
  GROUP BY Id_Booking ",ARRAY_A);

本文标签: databaseHow do join in query with WordPress