mysql - SQL Group by column and column value? -


i have hiring table below:

------------------------------------------------------ | slot_id  |  hired_days |  qty  |  amt  |  return   | -----------|-------------|-------|-------|-----------| |    1     |     30      |   5   |  100  |     0     | |    1     |     30      |  15   |  300  |     0     | |    1     |     30      |  12   |  170  |     1     | |    1     |     25      |  13   |  180  |     0     | |    1     |     30      |   4   |  180  |     1     | |    2     |     30      |  15   |  300  |     0     | ------------------------------------------------------ 

i want result grouped slot_id , hired_days grouping should done return value of 0 rows. result table needs display grouped rows , return 1 data. there way sql?

------------------------------------------------------- | slot_id  |  hired_days |   qty  |  amt  |  return   | |----------|-------------|--------|-------|-----------| |   1      |     30      |   20   |  400  |     0     | |   1      |     25      |   13   |  180  |     0     | |   1      |     30      |   12   |  170  |     1     | |   1      |     30      |    4   |  180  |     1     | |   2      |     30      |   15   |  300  |     0     | ------------------------------------------------------- 

you can use union operation

select slot_id,hired_days,sum(qty),sum(amt),return hiring return=0 group slot_id,hired_days  union  select slot_id,hired_days,qty,amt,return hiring return =1 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -