在同一列中对数据进行分组的SQL问题

时间:2015-05-20 00:09:13

标签: mysql sql

我有一些患者/医生数据,我需要能够根据医生程序的日期范围提取数据。问题是保存医生代码的列与程序代码的列相同。

行之间的唯一关联是,对于基于Doctor's Task的每个程序代码,该医生都有相应的程序代码。此外,还有一项费用和医生相应的“0”费用。

数据结构示例:

         Procedure Code          Description
            D1000                   Exam
            D1001                   Filling
            D1002                   Cleaning
            ZZ_Maria                Maria's Patient
            ZZ_Jose                 Jose's Patient

         Patient#          Procedure       Date Completed          $ Fee
            1000              D1000           1/1/2001                23
            1000              ZZ_Maria        1/2/2001                0
            1000              D1000           1/2/2001                25
            1000              D1001           1/3/2001                35
            1000              ZZ_Jose         1/4/2001                0
            1000              D1002           1/4/2001                45

所以我需要一个查询来显示针对由协调员

分组的指定日期范围完成的考试
    Date Range Specified:   1/1/2001 thru 2/30/2001

    Date            Coodinator      Name            Procedure       Fee
    1/2/2001        ZZ_Maria        John Doe        Exam            25
    2/10/2001       ZZ_Jose         John Doe        Exam            27

一个查询,显示为每个协调员列出的所有程序

    Date Range Specified:   1/1/2001 thru 2/30/2001

    Date            Coodinator      Name            Procedure       Fee
    1/2/2001        ZZ_Maria        John Doe        Exam            25
    1/3/2001        ZZ_Maria        John Doe        Filling         35
    1/4/2001        ZZ_Maria        John Doe        Cleaning        45
    2/10/2001       ZZ_Jose         John Doe        Exam            27

请帮助,我尝试过我能想到的一切。获取我想要的数据没有问题,但我不能让它以它需要的方式出现。

先谢谢。

1 个答案:

答案 0 :(得分:0)

您缺少如何获取患者姓名的信息,否则这是查询:

public class UnZip1 extends AsyncTask<Void, Integer, Integer> {

    {

    }

    private String _zipFile;   
    private String _location;
    private ProgressDialog mProgressDialog;
    private int per = 0;
    private Context _conti;
    private ProgressBar bar1;

    public UnZip1(Context conti,String zipFile, String location) {
        _conti = conti;
        _zipFile = zipFile;     
        _location = location;      
        bar1 = (ProgressBar)findViewById(R.id.pb1);
        _dirChecker("");   
    }  



    public void streamCopy(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[32 * 1024]; // play with sizes..
        int readCount;
        while ((readCount = in.read(buffer)) != -1) {
            out.write(buffer, 0, readCount);

        }




    }

    protected Integer doInBackground(Void... params) {
        try  {       
            ZipFile zip = new ZipFile(_zipFile);

            FileInputStream fin = new FileInputStream(_zipFile);       
            ZipInputStream zin = new ZipInputStream(fin);
            ZipEntry ze = null;       
            while ((ze = zin.getNextEntry()) != null) {

                Log.v("Decompress", "Unzipping " + ze.getName());          
                if(ze.isDirectory()) {           
                    _dirChecker(ze.getName());         
                } else {
                    // Here I am doing the update of my progress bar
                    Log.v("Decompress", "more " + ze.getName());

                    per++;
                    publishProgress(per);

                    FileOutputStream fout = new FileOutputStream(_location + ze.getName());

                    streamCopy(zin, fout);

                    zin.closeEntry();
                    fout.close();
                }      }       
            zin.close();    
        } catch(Exception e) {       
            Log.e("Decompress", "unzip", e);    
        }    
        return null;
    }    

    protected void onProgressUpdate(Integer... progress) {
       bar1.setProgress(per);
    }

    protected void onPostExecute(Integer... result) {
        Log.i("UnZip" ,"Completed. Total size: "+result);
    }

    private void _dirChecker(String dir) {     
        File f = new File(_location + dir);      
        if(!f.isDirectory()) {       
            f.mkdirs();     
        }   
    }

}
}