首先在过去3天内添加订单记录(排除某些产品类型),然后按其他列排序

时间:2017-08-17 05:24:30

标签: mysql

我有以下查询:

ObjectMapper

这个查询实际上做的是 -

  1. 首先在过去三天内添加的产品,
  2. 然后根据public class PlaylistActivity extends AppCompatActivity { private RecyclerView recyclerView; private SongsAdapter songsAdapter; SongsManager songsManager; String MEDIA_PATH = Environment.getExternalStorageDirectory() + ""; ArrayList<HashMap<String, String>> songList=new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_playlist); recyclerView=(RecyclerView)findViewById(R.id.playlistactivityrecyclerview); songsManager=new SongsManager(); songList =songsManager.getPlayList(MEDIA_PATH); songsAdapter=new SongsAdapter(songList); recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); recyclerView.setAdapter(songsAdapter); Toast.makeText(getApplicationContext(),"Hi",Toast.LENGTH_LONG).show(); } }
  3. 对产品进行排序
  4. 然后由public class SongsAdapter extends RecyclerView.Adapter<SongsAdapter.MyViewHolder>{ ArrayList<HashMap<String, String>> songList; public SongsAdapter(ArrayList<HashMap<String, String>> songList) { this.songList = songList; } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false); return new MyViewHolder(view); } @Override public void onBindViewHolder(MyViewHolder holder, int position) { holder.textView.setText(songlist.get(position).get("file_name")); } } @Override public int getItemCount() { return songList.size(); } public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { private TextView textView; public MyViewHolder(View itemView){ super(itemView); textView=(TextView)itemView.findViewById(R.id.listitemtextview); } @Override public void onClick(View v) { } } }
  5. 问题

    这非常有效,但在第一种情况下,如果public class SongsManager { public ArrayList<HashMap<String, String>> getPlayList(String rootPath) { ArrayList<HashMap<String, String>> fileList = new ArrayList<>(); try { File rootFolder = new File(rootPath); File[] files = rootFolder.listFiles(); //here you will get NPE if directory doesn't contains any file,handle it like this. for (File file : files) { if (file.isDirectory()) { if (getPlayList(file.getAbsolutePath()) != null) { fileList.addAll(getPlayList(file.getAbsolutePath())); } else { break; } } else if (file.getName().endsWith(".mp3")) { HashMap<String, String> song = new HashMap<>(); song.put("file_path", file.getAbsolutePath()); song.put("file_name", file.getName()); fileList.add(song); } } return fileList; } catch (Exception e) { return null; } } } 为2,我想要排除产品。

    任何人都可以告诉我如何实现这个目标

    SQLFIDDLE

    http://sqlfiddle.com/#!9/9bb584/1

    由于

1 个答案:

答案 0 :(得分:0)

对于那些在将来遇到类似问题的人,

实际上将查询修改为此。谢谢@Solarflare

SELECT
    prod.*,
    details.specification,
    details.warrantyinfo
FROM
    Products prod 
INNER JOIN  ProductDetails  details 
    ON details.product_id = prod.id 
WHERE 
    prod.is_approved = '1' 
    AND prod.is_active = '1'
    AND prod.is_deleted = '0' 
    ORDER BY  
        prod.created_at > '2017-08-14' AND prod.`listing_type`>2  DESC,  
        IF(prod.created_at > '2017-08-14' AND prod.`listing_type`>2, prod.created_at, FIELD(prod.listing_type,2,3,4,5,6))  DESC,  
        prod.is_featured DESC

这完美无瑕。

相关问题