PHP - 将列的值从一个表替换为另一个表

时间:2015-09-04 16:37:03

标签: php mysql join left-join

我必须去桌子。 (我正在使用$('video').click(function(){ this[this.paused ? 'play' : 'pause'](); }); )。它们具有相同的列数。让我通过展示一些内容向您展示:

表:MySQL

payment

表:Id TransactionCode InvoiceNumber 1 238694 322 2 518675 325 6 348611 401 13 750329 412

payment2

因此,表Id TransactionCode CustomerId 1 238694 32 2 NULL 36 13 79 48 是保存正确值的表,如您所见,这两个表几乎相同,我只需要移动payment中的所有数据并替换为{{ 1}}。

我想更新表payment2:

payment.TransactionCode

为了选择它,我使用了这个:

payment2.TransactionCode

它完美无缺。但是我如何 Id TransactionCode CustomerId 1 238694 322 2 518675 325 6 348611 401 13 750329 412 / SELECT payment.Id AS id, payment.TransactionCode AS TranC , payment2.TransactionCode AS TranC2 FROM payment LEFT JOIN payment2 ON payment.Id = payment2.Id 价值呢?!我试过这个,但它不起作用:

update

1 个答案:

答案 0 :(得分:0)

您可以JOIN UPDATE条款中的UPDATE payment JOIN payment2 ON (payment.Id=payment2.Id) AND ((payment.TransactionCode<>payment2.TransactionCode) OR (payment.TransactionCode IS NULL) AND (payment2.TransactionCode IS NOT NULL) OR (payment.TransactionCode IS NOT NULL) AND (payment2.TransactionCode IS NULL)) SET payment.TransactionCode = payment2.TransactionCode 表格,如下所示:

public class Customer
{
    public customerID;
    public customerName;
    public object _syncLockOrders = new object();
    .....
    private ObservableCollection<Order> _orderslist;
    public ObservableCollection<Order> orderslist
    {
        get 
        {
            if (_orderslist == null)
            {
                _orderslist = new ObservableCollection<Order>();
            }
            return _orderslist;
        } 
        private set {_orderslist = value;}}
    }
}

public class MainWindow : Window
{
    ...

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        var firstCustomer = Customers.customerslist.FirstOrDefault();

        custDataGrid.DataContext = Customers.customerslist;
        if (firstCustomer != null)
        {
            custDataGrid.SelectedItem = firstCustomer;
            ordersDataGrid.DataContext = firstCustomer.Orders.orderslist;
        } 
 ....
        BindingOperations.EnableCollectionSynchronization(firstCustomer.ordersList, firstCustomer._syncLockOrders);
}