永发信息网

sql语句高手请进来帮忙

答案:7  悬赏:40  手机版
解决时间 2021-05-06 10:48

SELECt shopping.sp_fzr, shopping.Sp_Address, shopping.Sp_Telephone, shopping.sp_id, shoppingbf.id, shoppingbf.Sp_Code,
shoppingbf.Fw_Date, shoppingbf.fw_shike,shoppingbf.Xcfw_date, shoppingbf.Visit_id, shoppingbf.Note,
shoppingbf.Users_id, Users.Users_name, shopping.sp_Name
FROM shoppingbf INNER JOIN
shopping ON shoppingbf.Sp_Code = shopping.sp_id INNER JOIN
Users ON shoppingbf.Users_id = Users.id

where shoppingbf.xcfw_date<='2009-10-30'

我想得到以下数据中,字段为sp_id的Xcfw_date 时间字段,时间最大的一条,怎么写啊,也就是说相同的字段为sp_id,只提取时间最大的一条数据

最佳答案

怎么不用order by Xcfw_date desc


select top 1 xxxxx from table where xxx order by xx desc


按照倒序排列,只取第一条

全部回答

最简单的办法 按时间排序 top 1

您好,图片看得不清楚QQ详谈,偶有时间

SELECt shopping.sp_fzr, shopping.Sp_Address, shopping.Sp_Telephone, shopping.sp_id, shoppingbf.id, shoppingbf.Sp_Code, shoppingbf.Fw_Date, shoppingbf.fw_shike,shoppingbf.Xcfw_date, shoppingbf.Visit_id, shoppingbf.Note, shoppingbf.Users_id, Users.Users_name, shopping.sp_Name FROM shoppingbf INNER JOIN shopping ON shoppingbf.Sp_Code = shopping.sp_id INNER JOIN Users ON shoppingbf.Users_id = Users.id

where shoppingbf.xcfw_date<='2009-10-30' and shoppingbf.Sp_Code in (select shoppingbf.Sp_Code from shoppingbf group by shoppingbf.Sp_Code having shoppingbf.Sp_Code > all)

SELECt distinct shopping.sp_fzr, shopping.Sp_Address, shopping.Sp_Telephone, shopping.sp_id, shoppingbf.id, shoppingbf.Sp_Code, shoppingbf.Fw_Date, shoppingbf.fw_shike,shoppingbf.Xcfw_date, shoppingbf.Visit_id, shoppingbf.Note, shoppingbf.Users_id, Users.Users_name, shopping.sp_Name FROM shoppingbf INNER JOIN shopping ON shoppingbf.Sp_Code = shopping.sp_id INNER JOIN

查询前加个去掉重复啊 distinct Users ON shoppingbf.Users_id = Users.id

where shoppingbf.xcfw_date<='2009-10-30'

select shopping.sp_id from shoppingbf inner join shoppingbf on shoppingbf.Sp_Code = shopping.sp_id

group by shoppingbf.Xcfw_date having shoppingbf.Xcfw_date in (select max(Xcfw_date) from shoppingbf)

..., shoppingbf.fw_shike,shoppingbf.Xcfw_date, shoppingbf.Visit_id...

找到shoppingbf.Xcfw_date改为max(shoppingbf.Xcfw_date) 加上函数

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
如何设置别人添加我为好友,需要验证通过?
08年4月份一直到现在没有报税,国税地税都没
怎样做好伊利奶粉的促销员啊
诺基亚E63中了恶意扣费程序,要硬格机还是软
有没有比李瑛更好的女人
女性私处有垂下来的肉,正常吗?
怎么样把自己想要的照片弄成空间背景
重庆鸡公煲(珠江店)地址在哪,我要去那里办事
怎样解决建房问题
为什么手机电池原装的比配件待机时间长?
狗为什么是四条腿,
怎样才能把人缘搞好?
看看这样的配置3000左右还行么?
某元素原子A的质子数为Z,已知B3-和A2-具有相
为什么我在我家玩QQ炫舞,QQ状态正常,却没有
推荐资讯
李若歆(xin),李梦熙哪个名字比较好,
吉祥馄饨·面公园路店在哪里啊,我有事要去这
中国(西部)国际珠宝交易中心地址在哪,我要去
为什么好多人要和狗或猫叫儿子或女儿呢
大明龙权结盟令旗的用处?
好听的歌给几个啊
CF会员都有什么功能?
服装纸样难学吗?
NDF科比1210-4版本去哪下载?
3Dmax8激活,内详!
求7月31号佛山高明新闻视频?
我们都己经做了地中海贫血的筛查了.只有一方
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?