sql语句高手请进来帮忙
解决时间 2021-05-06 10:48
- 提问者网友:了了无期
- 2021-05-06 02:27
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,只提取时间最大的一条数据
最佳答案
- 五星知识达人网友:西风乍起
- 2021-05-06 03:23
怎么不用order by Xcfw_date desc
select top 1 xxxxx from table where xxx order by xx desc
按照倒序排列,只取第一条
全部回答
- 1楼网友:零点过十分
- 2021-05-06 08:20
- 3楼网友:十年萤火照君眠
- 2021-05-06 07:17
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)
- 4楼网友:一叶十三刺
- 2021-05-06 06:11
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'
- 5楼网友:旧脸谱
- 2021-05-06 05:07
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) 加上函数
我要举报
大家都在看
推荐资讯