Yel*_*aYR 3 sql t-sql join sql-order-by
我需要创建一个仅提取customer_no列的查询(因为软件限制本身如此,因此我无法在外部进行编码)。但是我需要能够通过create_dt(相反)列对数据进行排序。代码/ SQL限制了我使用以下内容,因为为了对某些数据进行排序,必须将这些数据显示在select语句中。
我无法在其中显示它-有什么办法解决吗?
Select Distinct top 3500 a.customer_no
From T_CUSTOMER a WITH (NOLOCK)
JOIN (Select a1.customer_no From VXS_CUST_TKW a1 WITH (NOLOCK) Where a1.tkw in (141)) as e ON e.customer_no = a.customer_no
Where 1 = 1
order by a.create_dt desc
Run Code Online (Sandbox Code Playgroud)
当然可以。您的查询看起来像SQL Server,在其中可能会执行您想要的操作:
Select top 3500 a.customer_no
From T_CUSTOMER a WITH (NOLOCK) JOIN
(Select a1.customer_no
From VXS_CUST_TKW a1 WITH (NOLOCK)
Where a1.tkw in (141)
) e
ON e.customer_no = a.customer_no
Where 1 = 1
group by a.customer_no
order by max(a.create_dt) desc;
Run Code Online (Sandbox Code Playgroud)
MySQL中的等效查询如下所示:
Select a.customer_no
From T_CUSTOMER a JOIN
(Select a1.customer_no
From VXS_CUST_TKW a1
Where a1.tkw in (141)
) e
ON e.customer_no = a.customer_no
Where 1 = 1
order by a.create_dt desc
limit 3500;
Run Code Online (Sandbox Code Playgroud)
我删除了,distinct因为可能没有必要。如果是,请重新添加。