如果没有意义,请对标题的措辞表示不满。
我有一张包含订单和订单商品的表格。我拉了一个小订单,让你看看我指的是什么。
查看附件时:
这就是我要做的事情。我想拉下主要项目:
澄清更新:当Asm Main = 0时,我需要发货日期为非空。当Asm Main = 1时,发货日期并不重要,我只需要Date Promised为null。
SELECT bo.[Order Number],boi.[Unique ID]
from [Booked Order Items] boi JOIN [Booked Orders] bo ON boi.[Order Number] = bo.[Order Number]
WHERE boi.[Asm Main]=1 AND boi.[Date Promised] IS NULL
我可以清楚地执行第一步,但是为了使仅主要项目 ALL 的子项目没有空的发货日期以及上述条件,我无法弄明白。
答案 0 :(得分:0)
如果您只是想要订单,我会选择NOT EXISTS
:
SELECT bo.*
FROM [Booked Orders] bo
WHERE bo.[Date Promised] IS NULL AND
NOT EXISTS (SELECT 1
FROM [Booked Order Items] boi
WHERE boi.[Order Number] = bo.[Order Number] AND
boi.[Ship Date] IS NULL
);
(我不清楚ASM号码是如何适应的。)
如果您使用的是MySQL,可以通过以下方式获取项目:
SELECT boi.*
FROM [Booked Order Items] boi JOIN
[Booked Orders] bo
ON boi.[Order Number] = bo.[Order Number]
WHERE bo.[Date Promised] IS NULL AND
NOT EXISTS (SELECT 1
FROM [Booked Order Items] boi2
WHERE boi2.[Order Number] = bo.[Order Number] AND
boi2.[Ship Date] IS NULL
)
答案 1 :(得分:0)
使用与您的两个表的JOIN相同的逻辑,在查询A中取主要项目(以及using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
namespace WpfApp11
{
public partial class MainWindow : Window
{
public ObservableCollection<Entity> Entities { get; set; }
private int tempIndex = 1; // Always move box "2"
public MainWindow()
{
InitializeComponent();
DataContext = this;
Entities = new ObservableCollection<Entity>()
{
new Entity() { Name = "1", X=50, Y=50 },
new Entity() { Name = "2", X=150, Y=50 },
new Entity() { Name = "3", X=50, Y=150 },
new Entity() { Name = "4", X=150, Y=150 },
};
}
private void myCanvas_MouseMove(object sender, MouseEventArgs e)
{
}
private void myCanvas_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
}
private void myCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
}
private void myCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{
Point point = Mouse.GetPosition(sender as FrameworkElement);
if (e.LeftButton == MouseButtonState.Released)
{
Entities[tempIndex].X = (int)point.X;
Entities[tempIndex].Y = (int)point.Y;
}
}
}
public class Entity : INotifyPropertyChanged
{
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName]string name = null)
{
if (Equals(field, value))
{
return false;
}
field = value;
this.OnPropertyChanged(name);
return true;
}
protected void OnPropertyChanged([CallerMemberName]string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
#endregion
#region Property string Name
private string _Name;
public string Name { get { return _Name; } set { SetProperty(ref _Name, value); } }
#endregion
#region Property int X
private int _X;
public int X { get { return _X; } set { SetProperty(ref _X, value); } }
#endregion
#region Property int Y
private int _Y;
public int Y { get { return _Y; } set { SetProperty(ref _Y, value); } }
#endregion
}
}
)。通过计算这些子项目,为查询B中的子项应用类似的逻辑将$translate.instant(value)
设为Asm Num
,如果计数大于0,则表示您不希望该主要项目包含相应的Ship Date
,因为所有子项都必须为IS NULL
根据您的要求Asm Num
。因此加入Ship Date
和NOT NULL
时条件为and B.[sub_items_null_dates] = 0
。
A