比较一行与多行

时间:2018-09-10 19:58:33

标签: sql oracle oracle11g

例如:我还有另一个主表,其中包含以下数据

Create table dbo.Main_Table
(
ID INT,
SDate Date
)
Insert Into dbo.Main_Table   Values (1,'01/02/2018')
Insert Into dbo.Main_Table   Values (2,'01/30/2018')

Create table dbo.test
(
ID INT,
SDate Date
)
Insert Into dbo.test Values (1,'01/01/2018')
Insert Into dbo.test Values (1,'01/02/2018')
Insert Into dbo.test Values (1,'01/30/2018')

Insert Into dbo.test Values (2,'10/01/2018')
Insert Into dbo.test Values (2,'01/02/2018')
Insert Into dbo.test Values (2,'01/30/2018')

我想将主表数据与测试表进行比较。我们必须根据ID加入,如果找到日期匹配,则为“是”,否则为“否”。我们必须将一行与多行进行比较。

如果有任何问题,请告诉我,谢谢您。

1 个答案:

答案 0 :(得分:1)

像这样吗?

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wormholes.Views
{
    /// <summary>
    /// Interaction logic for TileView.xaml
    /// </summary>
    public partial class TileView : UserControl
    {
        public TileView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Paths to images to display, from back to front Z-index.
        /// </summary>
        public ObservableCollection<string> ImagePaths
        {
            get { return (ObservableCollection<string>)GetValue(ImagePathsProperty); }
            set { SetValue(ImagePathsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ImagePaths.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImagePathsProperty =
            DependencyProperty.Register(nameof(ImagePaths), typeof(ObservableCollection<string>), typeof(TileView), new PropertyMetadata(null));

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Property == ImagePathsProperty)
            {
                grid.Children.Clear();
                if (ImagePaths != null)
                {
                    foreach (var ip in ImagePaths)
                    {
                        try
                        {
                            var img = new Image { Source = new BitmapImage(new Uri(System.IO.Path.GetFullPath(System.IO.Path.Combine("Images", ip + ".png")), UriKind.RelativeOrAbsolute)), Width = Width, Height = Height };
                            grid.Children.Add(img);
                        }
                        catch (FileNotFoundException ex)
                        {
                            Console.Error.WriteLine($"Could not find image: {ip}");
                        }
                        catch (DirectoryNotFoundException ex)
                        {
                            Console.Error.WriteLine($"Could not find image: {ip}");
                        }
                    }
                }
            }
        }
    }
}

[编辑,阅读评论后-如果找到匹配项,则根本不需要该ID]

您在这里:

SQL> with main_table (id, sdate) as
  2    (select 1, date '2018-01-02' from dual union all
  3     select 2, date '2018-01-30' from dual union all
  4     select 3, date '2018-07-25' from dual
  5    ),
  6  test_table (id, sdate) as
  7    (select 1, date '2018-01-02' from dual union all
  8     select 2, date '2018-08-30' from dual
  9    )
 10  select m.id,
 11    m.sdate,
 12    case when m.sdate = t.sdate then 'yes' else 'no' end status
 13  from main_table m left join test_table t on t.id = m.id
 14  order by m.id;

        ID SDATE    STATUS
---------- -------- ------
         1 02.01.18 yes
         2 30.01.18 no
         3 25.07.18 no

SQL>