SELECT top 12 p.TITLE,u.PROVINCE,o.INPUTTIME, (CASE WHEN ltrim(u.RealName)='' OR u.RealName IS NULL THEN o.USERNAME ELSE LEFT(u.RealName,3)+(CASE u.Sex WHEN '男' THEN '先生' WHEN '女' THEN '姐' ELSE '**' END) END) AS USERNAME FROM (SELECT ORDERID,USERNAME,LEFT(CONVERT(varchar, INPUTTIME,120 ),10) AS INPUTTIME,PAYTIME FROM KS_Order WHERE STATUS='1') o LEFT JOIN KS_OrderItem i ON o.ORDERID=i.ORDERID LEFT JOIN KS_Product p ON i.PROID=p.ID LEFT JOIN KS_User u ON o.USERNAME=u.USERNAME ORDER BY o.PAYTIME DESC
语法不错的,语句需用到SQL商城版才可以 9.03前的版本若From前有关键字where代码上处理有点问题请升级到9.03版或至最后9.05版 建议升级到最新版