Select
Jim.GroupID As JimID,
Jim.Discount as JimDiscount,
Thai.GroupID As ThaiID,
Thai.Discount As ThaiDiscount
From
xTable As Jim
Left Join xTable As Thai On Jim.GroupID + 1 = Thai.GroupID And Jim.GroupID % 2 = 1
Where Thai.GroupID Is Not Null
Order By Jim.GroupID
Date :
2013-06-05 07:46:17
By :
ผ่านมา
No. 4
Guest
Enjoy with SQL
Code
Select
Jim.GroupID As JimID,
Jim.Discount as JimDiscount,
Thai.GroupID As ThaiID,
Thai.Discount As ThaiDiscount,
,((((ROW_NUMBER() Over (Order By Jim.GroupID) + 2)/3) - 1) % 3 ) + 1 As Good1500
From
xTable As Jim
Left Join xTable As Thai On Jim.GroupID + 1 = Thai.GroupID And Jim.GroupID % 2 = 1
Where Thai.GroupID Is Not Null
Order By Jim.GroupID
Date :
2013-06-05 08:08:46
By :
ผ่านมา
No. 5
Guest
Code
Select
Jim.GroupID As JimID,
Jim.Discount as JimDiscount,
Thai.GroupID As ThaiID,
Thai.Discount As ThaiDiscount,
,((((ROW_NUMBER() Over (Order By Jim.GroupID) + 2)/3) - 1) % 3 ) + 1 As Good1500
From
xTable As Jim
Left Join xTable As Thai On Jim.GroupID + 1 = Thai.GroupID And Jim.GroupID % 2 = 1
--Where Thai.GroupID Is Not Null
Order By Jim.GroupID
WITH cte
AS (
SELECT GroupID AS [ผัว]
,Discount AS [จ๋า]
,ROW_NUMBER() OVER (
ORDER BY GroupID
) - 1 AS rn
FROM xTable AS Ass
)
,cte0
AS (
SELECT *
FROM cte
WHERE rn % 3 = 0
)
,cte1
AS (
SELECT *
FROM cte
WHERE rn % 3 = 1
)
,cte2
AS (
SELECT *
FROM cte
WHERE rn % 3 = 2
)
SELECT *
FROM cte0
LEFT JOIN cte1 ON cte0.rn + 1 = cte1.rn
LEFT JOIN cte2 ON cte0.rn + 2 = cte2.rn
Date :
2013-06-06 19:00:20
By :
ผ่านมา
No. 8
Guest
ทดสอบประสิทธิภาพของ Query
Code
1. สร้างข้อมูลเพื่อทดสอบ
USE [JimThaiBigDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Insert_xTable]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @i As int
SET @i = 0
WHILE @i < 500000 -- ทดสอบ 5 แสน ระเบียน
BEGIN
Insert Into xTable Values(@i, @i + 1)
SET @i = @i + 1
END
END