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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -