SELECT Dish.DishID, DishImage.ImagePath, Dish.DishName, DishImage.DateAdded
FROM Dish LEFT OUTER JOIN
DishImage ON Dish.DishID = DishImage.DishID AND DishImage.Online = 1
WHERE (Dish.Online = 1)
ORDER BY Dish.Hits, Dish.DishID DESC查询结果DishID ImagePath DishName DateAdded
14 s172237.jpg DishName14 04-10 17:22:37.357
13 s64747.jpg Crispy 04-05 16:47:47.51
12 s171918.jpg Pork with Onions and Ginger 04-10 17:19:18.123
12 s172007.jpg Pork with Onions and Ginger 04-15 17:20:07.403
11 s171801.jpg Curry Chicken 04-10 17:18:01.937
10 s171705.jpg Honey Roast Pork 04-10 17:17:05.687
9 s171459.jpg DishName5 04-10 17:14:59.310我现在想得到下面的结果,按日期倒序就可以了DishID ImagePath DishName DateAdded
14 s172237.jpg DishName14 04-10 17:22:37.357
13 s64747.jpg Crispy 04-05 16:47:47.51
12 s172007.jpg Pork with Onions and Ginger 04-15 17:20:07.403
11 s171801.jpg Curry Chicken 04-10 17:18:01.937
10 s171705.jpg Honey Roast Pork 04-10 17:17:05.687
9 s171459.jpg DishName5 04-10 17:14:59.310
FROM Dish LEFT OUTER JOIN
DishImage ON Dish.DishID = DishImage.DishID AND DishImage.Online = 1
WHERE (Dish.Online = 1)
ORDER BY Dish.Hits, Dish.DishID DESC查询结果DishID ImagePath DishName DateAdded
14 s172237.jpg DishName14 04-10 17:22:37.357
13 s64747.jpg Crispy 04-05 16:47:47.51
12 s171918.jpg Pork with Onions and Ginger 04-10 17:19:18.123
12 s172007.jpg Pork with Onions and Ginger 04-15 17:20:07.403
11 s171801.jpg Curry Chicken 04-10 17:18:01.937
10 s171705.jpg Honey Roast Pork 04-10 17:17:05.687
9 s171459.jpg DishName5 04-10 17:14:59.310我现在想得到下面的结果,按日期倒序就可以了DishID ImagePath DishName DateAdded
14 s172237.jpg DishName14 04-10 17:22:37.357
13 s64747.jpg Crispy 04-05 16:47:47.51
12 s172007.jpg Pork with Onions and Ginger 04-15 17:20:07.403
11 s171801.jpg Curry Chicken 04-10 17:18:01.937
10 s171705.jpg Honey Roast Pork 04-10 17:17:05.687
9 s171459.jpg DishName5 04-10 17:14:59.310
insert tablename
select '2007-04-25 10:37:00', N'车公司', 5 ,N'载货车车身' union all
select '2007-04-25 10:37:00', N'车公司', 4 ,N'供应载货车车身' union all
select '2007-04-25 10:36:00', N'车公司', 3 ,N'供应载货车底盘' union all
select '2007-04-25 10:36:00', N'车公司', 2 ,N'载货车底盘' union all
select '2007-04-25 10:34:00', N'车公司', 1 ,N'供应宿营专用车' union all
select '2007-04-25 10:34:00', N'东风用车公司', 3 ,N'宿营专用车' union all
select '2007-04-25 10:33:00', N'东风用车公司', 2 ,N'供应越野汽车' union all
select '2007-04-25 10:33:00', N'东风用车公司', 1 ,N'越野汽车' union all
select '2007-04-25 10:32:00', N'东风公司', 6 ,N'供应康霸210康霸210' union all
select '2007-04-25 10:32:00', N'东风公司', 5 ,N'康霸210康霸210' union all
select '2007-04-25 10:31:00', N'东风公司', 4 ,N'供应东风大力神自卸车' union all
select '2007-04-25 10:31:00', N'东风公司', 3 ,N'东风大力神自卸车' union all
select '2007-04-25 10:30:00', N'东风公司', 2 ,N'供应东风运煤王' union all
select '2007-04-25 10:30:00', N'东风公司', 1 ,N'东风运煤王' union all
select '2007-04-25 10:29:00', N'商用车公司', 4 ,N'供应EQ3141G7D 东风工程车' union all
select '2007-04-25 10:29:00', N'商用车公司', 3 ,N'EQ3141G7D 东风工程车' union all
select '2007-04-25 10:28:00', N'商用车公司', 2 ,N'供应开路先锋自卸车' union all
select '2007-04-25 10:28:00', N'商用车公司', 1 ,N'开路先锋自卸车'select * from tablename a where (select count(1) from tablename where a.名称=名称 and a.排序<=排序)=1
select * from tablename a where not exists (select 1 from tablename where a.名称=名称 and a.排序<排序)drop table tablename
http://community.csdn.net/Expert/topic/5492/5492081.xml?temp=.738537