Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql query data transformation
    primarykey
    data
    text
    <p>I am trying to do transformation on a table in Mysql. I can't figure out how to do it. Could anyone tell me how to do it? The input and output is given. I would like to know how it is done?</p> <p>Input table</p> <pre><code>+-------------+------------+------------------+-------------------+ | Employee_ID | Start_Date | Termination_Date | Performance_Level | +-------------+------------+------------------+-------------------+ | 1 | 1/1/2007 | 3/1/2007 | Low | | 2 | 6/5/2004 | Null | Medium | | 3 | 4/3/2003 | Null | High | | 4 | 9/1/2002 | 4/15/2007 | Medium | | 5 | 4/6/2007 | 11/1/2007 | Low | | 6 | 7/1/2007 | Null | High | | 7 | 3/2/2005 | 8/1/2007 | Low | +-------------+------------+------------------+-------------------+ </code></pre> <p>Ouput Table</p> <pre><code>+---------+-----------------------------------+-----------------+-------------------+----------------+ | Period | Total_Employees_at_end_of_quarter | High_Performers | Medium_Performers | Low_Performers | +---------+-----------------------------------+-----------------+-------------------+----------------+ | Q1-2007 | 4 | 1 | 2 | 1 | | Q2-2007 | 4 | 1 | 1 | 2 | | Q3-2007 | 4 | 2 | 1 | 1 | | Q4-2007 | 3 | 2 | 1 | 0 | +---------+-----------------------------------+-----------------+-------------------+----------------+ </code></pre> <p>This is what I tried</p> <pre><code>select * from emp where date(sdate)&lt; date'2007-04-01' and (date(tdate)&gt; date'2007-03-31' or tdate is null); select * from emp where date(sdate)&lt; date'2007-07-01' and (date(tdate)&gt; date'2007-06-30' or tdate is null); select * from emp where date(sdate)&lt; date'2007-010-01' and (date(tdate)&gt; date'2007-09-30' or tdate is null); select * from emp where date(sdate)&lt; date'2008-01-01' and (date(tdate)&gt; date'2007-12-31' or tdate is null); </code></pre> <p>I have the individual queries but I want a single query which will give the outputs.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload