高分求教sql文,在线等
表结构:
id name
--------------
001 aaa
002 bbb
003 ccc
004 ddd
005 eee
006 fff
007 ggg
要求查询结果显示:
id name id name
-----------------------------------
001 aaa 004 ddd
002 bbb 005 eee
003 ccc 006 fff
007 ggg
即第n行和第n+3行同行显示,
access中sql怎么写?
------解决方案--------------------SELECT A.* FROM (
SELECT A.*,B.ID AS ID1,B.NAME FROM TT A LEFT JOIN TT B
ON B.ID=A.ID+3
WHERE NOT ISNULL(B.ID)) A
LEFT JOIN (
SELECT A.*,B.ID AS ID1,B.NAME FROM TT A LEFT JOIN TT B
ON B.ID=A.ID+3
WHERE NOT ISNULL(B.ID)) B
ON A.ID=B.ID1
WHERE ISNULL(B.ID1)
UNION SELECT * FROM (SELECT TOP 1 *, ' ', ' ' FROM TT ORDER BY ID DESC) AS DD;
还要对ID是否为偶数进行判断,你自己修改试试。