how can get single average row instead of multiple average rows? - mysql

I hava exam table in student database, i want show specific student with degree of each item in section 1,2 and avg section for each item
SELECT * FROM exam;
output:
id + numstudent + stage + item + exam +section + degree
---|------------|-------|------|------|--------|--------|
1 | stu_1991 | 2 | java | 1 | 1 | 70 |
--------------------------------------------------------|
2 | stu_1991 | 2 | java | 2 | 1 | 50 |
--------------------------------------------------------|
3 | stu_1991 | 2 | java | 1 | 2 | 60 |
--------------------------------------------------------|
4 | stu_1991 | 2 | java | 2 | 2 | 80 |
--------------------------------------------------------|
5 | stu_1991 | 2 | dart | 1 | 1 | 66 |
--------------------------------------------------------|
6 | stu_1991 | 2 | dart | 2 | 1 | 54 |
--------------------------------------------------------|
7 | stu_1991 | 2 | dart | 1 | 2 | 73 |
--------------------------------------------------------|
8 | stu_1991 | 2 | dart | 2 | 2 | 57 |
--------------------------------------------------------|
9 | stu_2222 | 1 | html | 1 | 1 | 55 |
--------------------------------------------------------|
10 | stu_2222 | 1 | html | 2 | 1 | 54 |
--------------------------------------------------------|
11 | stu_2222 | 1 | html | 1 | 2 | 73 |
--------------------------------------------------------|
12 | stu_2222 | 1 | html | 2 | 2 | 57 |
--------------------------------------------------------|
I want output like this:
id + numstudent + stage + item + exam +section + degree +avgsection+ avgfinal
---|------------|-------|------|------|--------|--------|----------|-----------|
1 | stu_1991 | 2 | java | 1 | 1 | 70 | | |
---------------------------------------------------------| | |
2 | stu_1991 | 2 | java | 2 | 1 | 50 | 60 | |
---------------------------------------------------------|----------| |
3 | stu_1991 | 2 | java | 1 | 2 | 60 | | |
---------------------------------------------------------| | |
4 | stu_1991 | 2 | java | 2 | 2 | 80 | 70 | 55 |
---------------------------------------------------------------------------------
5 | stu_1991 | 2 | dart | 1 | 1 | 66 | | |
---------------------------------------------------------| | |
6 | stu_1991 | 2 | dart | 2 | 1 | 54 | 60 | |
---------------------------------------------------------|----------| |
7 | stu_1991 | 2 | dart | 1 | 2 | 73 | | |
---------------------------------------------------------| | |
8 | stu_1991 | 2 | dart | 2 | 2 | 57 | 65 | 62.5 |

Related

I want to retrieve which scheduler is scheduled for a particular day

+-----+--------------------------------------------------+--------+--------------------+---------------+---------------+---------------+--------------------------------------+-------------------------+-------------------+--------------------------------------------------------------------------------------------------------+--------------------------+--------+----------------+--------------------------------------+---------+
| ID | Name | Action | Created By Use Rid | Created Date | Days | Enterprise ID | Job ID | Last Updated By Use Rid | Last Updated Date | Relays | Sch Time | Status | Timezone | Trigger ID | User ID |
+-----+--------------------------------------------------+--------+--------------------+---------------+---------------+---------------+--------------------------------------+-------------------------+-------------------+--------------------------------------------------------------------------------------------------------+--------------------------+--------+----------------+--------------------------------------+---------+
| 30 | ios | 1 | 2 | 1559739565592 | | 2 | ef29baba-534d-4151-80d3-f5a589cf7c22 | 2 | 1559739565592 | 74 | 2019-06-05T13:04:00.000Z | 2 | Asia/Kolkata | 0492dc45-6671-4064-baef-8654761b67f2 | 2 |
| 31 | iot | 0 | 2 | 1559739617863 | 1,2,3,4,5,6,7 | 2 | 85e4a611-37dc-45d3-8a2f-243e6d4e0962 | 2 | 1575869484168 | 508,509,504,505,506,507 | 2019-12-09T13:50:00.000Z | 0 | Asia/Kolkata | b8a71ee4-94bd-4d2b-b875-7ac1468fad11 | 2 |
| 32 | Daily-8:50 Pm | 1 | 2 | 1559747777019 | | 2 | 3f87f532-6289-4016-a6d4-2a76baf4ffb5 | 2 | 1559749199040 | 45,46,47,48,50,51,52,61,62,63,64,65,302,303,73,74,75,76,77,53,54,55,56,57,58,59,60,49,66,67,68,304,305 | 2019-06-05T15:41:00.000Z | 2 | Asia/Kolkata | 6f1b873b-1e96-47bd-b723-4f50d5534f89 | 2 |
| 33 | TVOffSchedular | 0 | 2 | 1559933346322 | 1,2,3,4,5,6,7 | 4 | 1935f0cf-cdf9-4bdf-895d-9e6dc6c4ddff | 2 | 1560453392696 | 321,325 | 2019-06-13T19:20:00.000Z | 0 | Asia/Kolkata | c6bf383d-7bd7-4364-b077-e8bb3ad857f7 | 2 |
| 34 | TVOnMorning | 1 | 2 | 1559933392595 | 1,2,3,4,5,6,7 | 4 | d90d5c17-46b9-46cc-bb33-07557bf97684 | 2 | 1559933392595 | 321,325 | 1970-01-01T00:00:00.000Z | 2 | Asia/Kolkata | a131188d-aa7d-4132-995e-035e172566a7 | 2 |
| 35 | MorningOfficeON | 1 | 2 | 1560004379991 | 1,2,3,4,5,6 | 2 | 8b9163e7-bdea-4ee3-b827-3ab3d4728a0c | 2 | 1561881126773 | 49 | 2019-06-08T02:30:00.000Z | 0 | Asia/Kolkata | 926e809f-b1fb-4d3c-8da7-b048c0366a3a | 2 |
| 36 | EveningOfficeOFF | 0 | 2 | 1560005726195 | 1,2,3,4,5,6 | 2 | a7161d66-9ae4-4eb9-bc6e-ded6bd01a766 | 2 | 1560261033555 | 49 | 2019-06-11T14:00:00.000Z | 0 | Asia/Kolkata | dc45718f-aad4-4eb2-9b94-8a8bc4444385 | 2 |
| 37 | Good night | 1 | 3 | 1560088585521 | 1,2,3,4,5,6,7 | 3 | 4e8eedd1-956d-4922-9715-8f9b7bf221cb | 3 | 1560088585521 | 253,363 | 1970-01-01T14:00:00.000Z | 2 | Asia/Kolkata | 39a8fb76-06d6-4fdd-8c1f-827c3c1e2c24 | 3 |
| 38 | Good night off | 0 | 3 | 1560088719173 | 1,2,3,4,5,6,7 | 3 | c0a9dfdd-7b1b-4a9e-a9f1-b31d927d995e | 3 | 1560088719173 | 253,363 | 1969-12-31T19:30:00.000Z | 2 | Asia/Kolkata | 61cfacdd-f2c8-46c9-b192-228aef33cc59 | 3 |
| 39 | ApplicationON | 1 | 2 | 1560140790669 | 1,2,3,4,5,6,7 | 2 | 8f602cc4-8fe7-416a-b563-9b25cd008e5b | 2 | 1560141163056 | 45,46,47,48,50,51,52 | 2019-06-10T04:35:00.000Z | 0 | Asia/Kolkata | 5bab6ae0-7c7b-487c-9e72-d6200e0985a2 | 2 |
| 40 | ApplicationMorningOFF | 0 | 2 | 1560140849363 | 1,2,3,4,5,6,7 | 2 | 7d34c4f1-3638-4355-a14c-622bf733e23e | 2 | 1560141176600 | 45,46,47,48,50,51,52 | 2019-06-10T04:40:00.000Z | 0 | Asia/Kolkata | 4cd78892-c2b2-493e-a839-b270eff5aea5 | 2 |
| 41 | DesignNoonOFF | 0 | 2 | 1560241956756 | 1,2,3,4,5,6,7 | 2 | 00d3437b-a062-4f32-bb37-200574cac235 | 2 | 1567674559401 | 512,513,514,515 | 2019-09-05T08:15:00.000Z | 0 | Asia/Kolkata | b10d1ded-60a3-4adf-ba6c-743ec3dc4f29 | 2 |
| 42 | DesignNoonON | 1 | 2 | 1560241995428 | 1,2,3,4,5,6,7 | 2 | f3e3807c-7fad-4b08-bb18-439222f8d454 | 2 | 1567674587127 | 512,513,514,515 | 2019-09-05T08:30:00.000Z | 0 | Asia/Kolkata | c53e9069-164e-430a-89be-913c8127a767 | 2 |
| 43 | blockchain-test | 1 | 2 | 1560255684868 | 1,2,3,4,5,6,7 | 2 | 4ac65798-682e-447d-b6cf-813308f05efe | 2 | 1560257490068 | 45,46,47,48,50,51,52,61,62,63,64,65,302,73,74,75,76,53,54,57,58,59,60 | 2019-06-11T12:52:00.000Z | 2 | Asia/Calcutta | 8e7640ea-0223-4a9b-abdc-73c139f8e6fa | 2 |
| 44 | NightLampON | 1 | 2 | 1560360082007 | 1,2,3,4,5,6,7 | 4 | b5aee8d5-8013-4303-88df-6a5e3bc7330e | 2 | 1560360082007 | 322 | 1970-01-01T17:25:00.000Z | 0 | Asia/Kolkata | d0f3a1b5-93f3-4858-be5f-4837e62dd9bf | 2 |
| 45 | blockchain-off | 1 | 2 | 1560432958716 | 1,2,3,4,5,6,7 | 2 | a3d89bb2-3710-4f8e-9814-1e6942d1a405 | 2 | 1560432958716 | 53,54,57,59,60 | 2019-06-13T13:45:00.000Z | 0 | Asia/Calcutta | a0ccdcb6-a55e-48e2-9391-60d62e10fe4a | 2 |
| 46 | AllLightOffExceptOfficeMaster | 0 | 2 | 1560524588879 | | 2 | 64939311-522e-4877-b53f-e44ff78200b7 | 2 | 1560524588879 | 45,46,47,48,50,51,52,61,62,63,64,302,303,73,74,75,76,77,53,54,55,56,57,58,59,60 | 2019-06-14T15:10:00.000Z | 0 | Asia/Kolkata | 4a799d93-877c-4d19-b19a-40b6b9767564 | 2 |
| 47 | NightLampOFF | 0 | 2 | 1560533195543 | 1,2,3,4,5,6,7 | 4 | c844b235-3851-4692-ab14-4ee31b5d9404 | 2 | 1560620178500 | 322 | 2019-06-15T17:40:00.000Z | 0 | Asia/Kolkata | a48c0a99-76cd-4268-b946-8d63408aa234 | 2 |
| 48 | TVON | 1 | 2 | 1561124197968 | 1,2,3,4,5,6,7 | 4 | b0617f91-54b2-48bc-9cf9-2f42fb1526c4 | 2 | 1571035693157 | 321,325 | 2019-06-20T23:30:00.000Z | 0 | Asia/Kolkata | 93d07355-1c95-4faa-ac5c-73b0c68b5323 | 2 |
| 49 | panel light/Inside logo on | 1 | 3 | 1561492261954 | 1,2,3,4,5,6 | 3 | 736609ff-6391-474a-9556-85eff54f2fd8 | 3 | 1561492261954 | 359,360,361,364 | 2019-06-26T14:00:00.000Z | 2 | Asia/Kolkata | 84de41a7-a141-49d3-8bf2-8a9a229a8c56 | 3 |
| 50 | Outside Board/panel/focus light ON | 1 | 3 | 1562096267147 | 1,2,3,4,5,6,7 | 3 | 37d4f238-15b3-4a1a-bac1-a050d61792f7 | 3 | 1572442799792 | 894 | 1970-01-01T13:45:00.000Z | 2 | Asia/Kolkata | 3610c4b9-6180-4640-a078-3e310d80b4dd | 3 |
| 51 | Outside Board/Panel/Focus light OFF | 0 | 3 | 1562096428205 | 1,2,3,4,5,6,7 | 3 | 7ef0d450-39f9-4449-beec-c46416c3ebb2 | 3 | 1572442815806 | 894 | 2019-10-30T16:30:00.000Z | 2 | Asia/Kolkata | 8d9fe67d-7d39-4edb-8191-ea8af176b5d7 | 3 |
| 52 | Inside Logo/Panel/Display/Ganpati/Entry light ON | 1 | 3 | 1562096734383 | 1,2,3,4,5,6 | 3 | 4b6bab36-889a-45ca-969c-a1cecea1f42f | 3 | 1562096734383 | 110,111,359,360,361,364 | 2019-07-03T13:30:00.000Z | 2 | Asia/Kolkata | c08cc35a-8e64-4d17-a673-4bfddb2f1c92 | 3 |
| 53 | Inside Logo/Panel/Display/Ganpati/Entrance OFF | 0 | 3 | 1562097007454 | 1,2,3,4,5,6 | 3 | 54de42a4-f28e-494a-9ec3-56e22e7956e9 | 3 | 1562257875176 | 110,111,359,360,361,364 | 2019-07-03T16:30:00.000Z | 2 | Asia/Kolkata | ffbf0fcd-e6ae-41ba-8873-0d2bbd5d3cd0 | 3 |
| 54 | EveningOfficeON | 1 | 2 | 1562852792955 | | 2 | b4c3b59f-8157-4260-b0c0-a76b739e857b | 2 | 1562852792955 | 45,46,47,48,61,62,63,64,49 | 2019-07-11T14:01:00.000Z | 0 | Asia/Kolkata | 4be1a145-8e21-405e-990d-f85d0c3657bf | 2 |
| 55 | WaterCoolerON | 1 | 2 | 1564217226090 | 1,2,3,4,5,6,7 | 2 | 1e9c429f-9a51-4147-815b-efad95330baa | 2 | 1564217226090 | 489 | 1970-01-01T00:30:00.000Z | 0 | Asia/Kolkata | 4b9413ae-6d13-4117-bc8d-36f02c462b05 | 2 |
| 56 | WaterCoolerOff | 0 | 2 | 1564217269330 | 1,2,3,4,5,6,7 | 2 | 0f2c1112-dd26-43eb-8390-a1bba53789de | 2 | 1564217269330 | 489 | 1970-01-01T14:30:00.000Z | 0 | Asia/Kolkata | 907e4ee5-367a-4b4b-bc6b-716eeed4c8b8 | 2 |
| 57 | Test 1 | 1 | 28 | 1567236412976 | | 6 | 2c8276b3-a946-475c-a0e9-7e55569cadae | 28 | 1567236412976 | 553 | 2019-08-31T07:28:00.000Z | 2 | IST | dc1fec52-8c98-4832-b01a-a3a91f0b6058 | 28 |
| 58 | Test 3 | 1 | 28 | 1567236499938 | | 6 | fc820b65-a04c-4ecf-9876-2bd4bb8a8816 | 28 | 1567237094910 | 556,557 | 2019-08-31T07:39:00.000Z | 2 | IST | ceca92e5-765c-4f54-97ba-77447147276f | 28 |
| 59 | Test 1.1 | 1 | 28 | 1567236608884 | | 6 | 985e07c0-3a53-4884-a169-19e8a9ae630b | 28 | 1567236608884 | 553 | 2019-08-31T07:32:00.000Z | 2 | IST | f1a18b94-ef35-46a7-afbe-c75e743185fe | 28 |
| 60 | Outside C&C Ledlight On | 1 | 3 | 1570365557312 | 1,2,3,4,5,6,7 | 3 | ad17d61e-549e-44f1-99db-b50105d069b3 | 3 | 1574947645835 | 893 | 2019-11-28T12:30:00.000Z | 0 | Asia/Kolkata | 82b0fc02-c98c-4b12-9d8a-3ba2897d1aa7 | 3 |
| 61 | test | 0 | 2 | 1570532481972 | 1 | 2 | 2d058c32-89f8-4709-ba77-cca2c677334d | 2 | 1570532481972 | 524,525,526,527,529,530,531 | 2019-10-08T11:00:00.000Z | 2 | Africa/Lusaka | 722aece6-39d5-44be-bace-967180cd449f | 2 |
| 62 | Outside C&C Ledlight Off | 0 | 3 | 1570647085459 | 1,2,3,4,5,6,7 | 3 | 24c4831d-3491-4fa9-a8e2-dab21a94aa93 | 3 | 1572636959040 | 893 | 2019-10-29T19:00:00.000Z | 0 | Asia/Kolkata | 41c21970-faf8-4699-9a97-a49e1b28f3ce | 3 |
| 63 | bedroom allout 1 | 1 | 2 | 1571346220354 | 1,2,3,4,5,6,7 | 7 | 9ba4ec5b-c645-4cf6-bede-59fa79073134 | 2 | 1574015422525 | 662 | 1970-01-01T17:03:00.000Z | 0 | Asia/Calcutta | 4aff33ae-6af6-45f3-8407-f67a6f344e4b | 2 |
| 64 | bedroom allout off | 0 | 2 | 1571346263753 | 1,2,3,4,5,6,7 | 7 | 8cd3c6ac-0ea6-49b9-af09-10e9dcb3847b | 2 | 1571346263753 | 662 | 1970-01-01T01:04:00.000Z | 0 | Asia/Calcutta | 4ecfcf3f-110c-44b2-9a8d-3f35f1d5a295 | 2 |
| 65 | PIR Enable | 1 | 25 | 1571649294987 | 1,2,3,4,5,6,7 | 9 | c142b8f1-77d6-46a2-8f45-46ad3770a3c4 | 25 | 1571661763643 | 756 | 2019-10-21T13:00:00.000Z | 2 | Asia/Kolkata | 05fc4108-f65a-449f-a211-10e76e080196 | 25 |
| 66 | PIR Disable | 0 | 25 | 1571649351212 | 1,2,3,4,5,6,7 | 9 | 894ef781-cb8f-4139-907f-5d20fc5a0861 | 25 | 1571649351212 | 756 | 2019-10-21T01:30:00.000Z | 2 | Asia/Kolkata | 0f927aca-f592-44bb-9a7f-67544aa32223 | 25 |
| 67 | testing 22 | 1 | 2 | 1571734869588 | | 7 | 2fe74039-d25e-4384-bc4a-dd63843de063 | 2 | 1574015556036 | 639 | 2019-11-20T09:03:00.000Z | 0 | Asia/Calcutta | 86cfd858-367a-4a0b-b7eb-35e1096b56f4 | 2 |
| 68 | mobile charger | 0 | 23 | 1572199190164 | 1,2,3,4,5,6,7 | 11 | 7d536ef8-d24a-4a53-94c0-6c52a441312a | 23 | 1575485933026 | 773,774 | 2019-12-04T21:00:00.000Z | 0 | Asia/Calcutta | fc8b10b3-43a5-497c-86b9-bd55a80cfe4a | 23 |
| 69 | Outside Focus light On | 1 | 3 | 1572637078856 | 1,2,3,4,5,6,7 | 3 | 9a889394-8102-42a0-836a-43a7ffb5c7bf | 3 | 1572983697418 | 922 | 2019-11-06T12:30:00.000Z | 0 | Asia/Kolkata | 4747ca5e-736b-4b80-b7a4-9abfe33f0e77 | 3 |
| 70 | Outside Focus light Off | 0 | 3 | 1572637169312 | 1,2,3,4,5,6,7 | 3 | 1a283075-37e6-4152-a716-a8b63ef62f56 | 3 | 1572637169312 | 922 | 1969-12-31T18:35:00.000Z | 0 | Asia/Kolkata | fa79f7f6-bde4-4d87-96fd-b570ad47a57c | 3 |
| 71 | Ganpati/Display On | 1 | 3 | 1572637346879 | 2,3,4,5,6,7 | 3 | 6ae8c9ca-e26b-48b8-a3be-ef2d41b0a0d6 | 3 | 1574943671391 | 924,926,894 | 2019-11-28T12:30:00.000Z | 0 | Asia/Kolkata | 0027b2eb-efa2-41ff-ac24-50483eec4632 | 3 |
| 72 | Ganpati/Display Off | 0 | 3 | 1572637442853 | 2,3,4,5,6,7 | 3 | 0bb73aca-c82d-4459-922b-cb3592783ae9 | 3 | 1574943713949 | 924,926,894 | 2019-11-28T16:30:00.000Z | 0 | Asia/Kolkata | f8fb596e-dd42-4227-98cb-03a8dcbee9bb | 3 |
| 73 | panel/Logo/Table logo/ Light On | 1 | 3 | 1572638062814 | 2,3,4,5,6,7 | 3 | ab78a500-af55-4c8c-84a8-fdbbe76404f4 | 3 | 1572638089623 | 853,855 | 2019-11-02T12:30:00.000Z | 0 | Asia/Kolkata | 0ef71b02-744c-4755-b7dc-bc51dd727fe9 | 3 |
| 74 | all-out-off | 0 | 13 | 1572887848318 | 2,3,4,5,6 | 10 | 213f3bab-332a-4992-9d2d-7e38cf48dbfd | 13 | 1572887848318 | 838 | 2019-11-04T01:30:00.000Z | 0 | Asia/Calcutta | 70938fed-0053-443e-b302-e0f8e25826bb | 13 |
| 75 | mbroom-fan-off | 0 | 13 | 1572888838651 | 1,2,3,4,5,6,7 | 10 | ae1b74c2-2ad7-4182-9b4d-3f15812edbe8 | 13 | 1572974583661 | 834 | 2019-11-04T20:45:57.000Z | 0 | Asia/Calcutta | e87e19e4-d8ae-45b4-b575-1110d1368648 | 13 |
| 76 | PIR Enable | 1 | 25 | 1572944519175 | 1,2,3,4,5,6,7 | 9 | 6fc17694-4fc5-443e-92ee-ed1132a2ec35 | 25 | 1572944519175 | 758 | 2019-11-05T12:46:00.000Z | 0 | Asia/Kolkata | 46ea68cd-7e11-4003-bdfb-54aab6ba3923 | 25 |
| 77 | PIR Disable | 0 | 25 | 1572944690715 | 1,2,3,4,5,6,7 | 9 | ae7a333c-ff75-4c8b-bcae-92b308180b93 | 25 | 1573197064859 | 758 | 2019-11-06T00:20:00.000Z | 0 | Asia/Kolkata | 6a41e2f1-d029-4d28-9ce7-b2adebb59dab | 25 |
| 78 | test 1 | 1 | 2 | 1573129815561 | | 16 | ab60b929-48ed-43ab-9a89-45bfc0a10ee3 | 2 | 1573129815561 | 1030 | 2019-11-07T12:32:13.000Z | 0 | Asia/Kolkata | 80c7d1b2-68b4-425e-91b4-d82544d66dfc | 2 |
| 79 | pir en test | 1 | 25 | 1573196361376 | 1,2,3,4,5,6,7 | 9 | a206b1f6-f1e8-4c12-a97f-b7d217fd344a | 25 | 1573196739778 | 758 | 2019-11-08T07:08:00.000Z | 2 | Asia/Kolkata | dc23b8ee-2da0-42a3-a6d0-35a328035e12 | 25 |
| 80 | pir dbtest | 0 | 25 | 1573196399643 | 1,2,3,4,5,6,7 | 9 | 5d133d17-8495-4e34-aa6c-ea13344ddfdc | 25 | 1573196765147 | 758 | 2019-11-08T07:09:00.000Z | 2 | Asia/Kolkata | b431f3fc-f541-4912-b698-83f574c1c811 | 25 |
| 81 | living-off | 0 | 13 | 1573408027950 | | 10 | cac70a87-98b3-405f-a6da-2ac6f1c3a344 | 13 | 1573408137563 | 813 | 2019-11-10T20:30:56.000Z | 0 | Asia/Calcutta | 7b91172a-da7b-4f94-bf92-7915b51fce98 | 13 |
| 82 | ro on | 1 | 2 | 1573416862256 | 1,2,3,4,5,6,7 | 7 | 22e7e1ab-d2f3-483e-bcc5-3aa595feedb8 | 2 | 1573416862256 | 672 | 1970-01-01T00:08:00.000Z | 0 | Asia/Calcutta | 747f6396-77b7-4bab-93a2-6c6715b3e87f | 2 |
| 83 | RO off | 0 | 2 | 1573473725301 | 1,2,3,4,5,6,7 | 7 | eed1acbd-0850-4dc1-ad65-2528eb630389 | 2 | 1573473725301 | 672 | 1969-12-31T19:01:00.000Z | 0 | Asia/Calcutta | 89a511e2-52f6-45f3-9257-78b7f9f41bc2 | 2 |
| 84 | Test | 1 | 42 | 1573738374195 | | 17 | fca106ba-af83-4bae-8855-aa4d9edd4484 | 42 | 1573738590203 | 1133,1134,1135,1136 | 2019-11-14T13:38:29.000Z | 0 | Asia/Kolkata | f668dc34-db5b-4f34-a5a1-ee7649bc093d | 42 |
| 85 | entrance | 0 | 42 | 1573738946510 | | 17 | ce332a00-b3ca-45cc-9c1d-c3ead60845fd | 42 | 1573738946510 | 1133 | 2019-11-14T13:47:25.000Z | 0 | Asia/Kolkata | c7b912db-096a-4836-8b1d-0b52197922c5 | 42 |
| 86 | ronak bedroom charger | 1 | 15 | 1573827203905 | 1,2,3,4,5,6,7 | 15 | a31cc0a3-cfcd-4a57-8a72-f292893c4de9 | 15 | 1574274253149 | 1103 | 2019-11-14T23:30:00.000Z | 0 | Asia/Kolkata | 91a3e0c7-f750-42ca-84e0-af4bbb7ef839 | 15 |
| 87 | ronak bedroom plug off | 0 | 15 | 1573827259380 | 1,2,3,4,5,6,7 | 15 | 7f9e1f0f-e126-4bdd-acce-967bfb785c25 | 15 | 1574274268343 | 1103 | 2019-11-15T01:30:00.000Z | 0 | Asia/Kolkata | dc3b7742-711c-46c5-9395-38c9568d32dc | 15 |
| 88 | fan off | 0 | 15 | 1573845123332 | 1,2,3,4,5,6,7 | 15 | d5c68535-499a-436d-844f-8d0d7140d2da | 15 | 1573845123332 | 1096 | 2019-11-15T20:32:00.000Z | 0 | Asia/Kolkata | a014d04c-48dc-4ec4-a56f-90383387c241 | 15 |
| 89 | master beroom all out on | 1 | 20 | 1574014827858 | 1,2,3,4,5,6,7 | 8 | f25ae2d2-9414-418a-878b-1545a956d5fe | 20 | 1574014827858 | 700 | 2019-11-17T17:00:00.000Z | 0 | Asia/Kolkata | 3cded4f6-9740-43fa-b921-b5b9deb5bdb5 | 20 |
| 90 | master bedroom plug 4 | 0 | 20 | 1574015013470 | 1,2,3,4,5,6,7 | 8 | 1daabfe0-ccaa-4821-8658-c556541771a4 | 20 | 1574042395372 | 700 | 2019-11-18T00:30:00.000Z | 0 | Asia/Kolkata | fa0aad18-fe38-4e2f-8753-caef702ab74c | 20 |
| 91 | light on | 0 | 22 |
+-----+--------------------------------------------------+--------+--------------------+---------------+---------------+---------------+--------------------------------------+-------------------------+-------------------+--------------------------------------------------------------------------------------------------------+--------------------------+--------+----------------+--------------------------------------+---------+
In the below data the sch time needs to be compared with Days ie when the Days column is null then sch Time should be the output and when it is 1,2,3,4,5,6,7 then case when 1 then return sunday, case when 2 then return monday,case when 3 then return tues, case when 4 then return wed, case when 5 then return thur, case when 6 then return fri, case when 7 then return sat. should be the output The data should be time and date sorted decreasing
Please check the below query and put your table name at the place Your_table.
ALTER TABLE dbo.dates ADD update_stat BIT DEFAULT(0) --You can add this in current table or temp table
WHILE EXISTS (
SELECT TOP 1 update_stat
FROM Your_Table
WHERE update_stat = 0
ORDER BY Id
)
BEGIN
DECLARE #days VARCHAR(100)
DECLARE #datepart VARCHAR(10)
DECLARE #Id INT
SET #datepart = DATEPART(dw, getdate())
SET #days = (
SELECT TOP 1 days
FROM dbo.dates
WHERE days IS NOT NULL
ORDER BY ID
)
SET #ID = (
SELECT TOP 1 ID
FROM dbo.dates
WHERE days IS NOT NULL
ORDER BY ID
)
IF CHARINDEX(#datepart, #days) > 0
BEGIN
UPDATE Your_Table
SET update_stat = 1
WHERE id = #Id
END
SELECT
SELECT DATEPART(d, getdate()) AS DaysNo
,CASE DATEPART(WEEKDAY, GETDATE())
WHEN 1
THEN 'SUNDAY'
WHEN 2
THEN 'MONDAY'
WHEN 3
THEN 'TUESDAY'
WHEN 4
THEN 'WEDNESDAY'
WHEN 5
THEN 'THURSDAY'
WHEN 6
THEN 'FRIDAY'
WHEN 7
THEN 'SATURDAY'
END AS DaysName
,*
FROM Your_Table
WHERE update_stat = 1
You can insert the new column the update_stat either in the same table or you can insert all the existing table data into temp table and then add a update_stat column using below query and rest are same start from WHILE Loop.
SELECT * INTO ##tempTable
FROM Your_Table
ALTER TABLE dbo.dates ADD update_stat BIT DEFAULT(0)---rest are same..

how to store multiple id in multiple column

first table :
table Name : ssc_course;
+---------------+-----------------+------------+
| ssc_course_id | ssc_course_name | qualify_id |
+---------------+-----------------+------------+
| 1 | HSC | 1 |
| 2 | Diploma | 1 |
| 3 | ITI | 1 |
+---------------+-----------------+------------+
second table :
table name :ssc_stream
+---------------+--------------------+-----------------+
| ssc_stream_id | ssc_stream_name | ssc_course_id(fk) |
+---------------+--------------------+-----------------+
| 1 | Science | 1 |
| 2 | Commers | 1 |
| 3 | Arts | 1 |
| 17 | Computer Engg | 2 |
| 18 | Mechanical Engg | 2 |
| 19 | Civil Engg | 2 |
| 20 | Electronics & TELE | 2 |
| 21 | E&TC | 2 |
+---------------+--------------------+-----------------+
third table :(master table)
table name : ssc_college
+------------+--------------+---------------+---------------+-
| ssc_clg_id | clg_login_id | ssc_stream_id | ssc_course_id |
+------------+--------------+---------------+---------------+-
| 9 | 2 | 1 | 1 |
| 10 | 2 | 1 | 1 |
| 11 | 2 | 2 | 1 |
| 12 | 2 | 2 | 1 |
| 13 | 2 | 3 | 1 |
| 14 | 2 | 3 | 1 |
| 15 | 3 | 1 | 1 |
| 16 | 3 | 1 | 1 |
| 17 | 3 | 2 | 1 |
| 18 | 3 | 2 | 1 |
| 19 | 3 | 3 | 1 |
| 20 | 3 | 3 | 1 |
| 21 | 4 | 1 | 1 |
| 22 | 4 | 1 | 1 |
| 23 | 4 | 2 | 1 |
| 24 | 4 | 2 | 1 |
| 25 | 4 | 3 | 1 |
| 26 | 4 | 3 | 1 |
| 27 | 5 | 17 | 2 |
| 28 | 5 | 17 | 2 |
| 29 | 5 | 18 | 2 |
| 30 | 5 | 18 | 2 |
| 31 | 5 | 19 | 2 |
| 32 | 5 | 19 | 2 |
| 33 | 5 | 20 | 2 |
| 34 | 5 | 20 | 2 |
| 35 | 5 | 21 | 2 |
| 36 | 5 | 21 | 2 |
| 38 | 6 | 17 | 2 |
| 39 | 6 | 17 | 2 |
| 40 | 6 | 18 | 2 |
*************************************************************
I am trying to save course,stream id's into ssc_college table.
1 course have multiple stream how can i insert this type of values
ex. course 1-diploma and this course have multiple stream like-
1.comp. engg , 2.mechanical ,3.e&tc i want to add course id and
stream id at a time of third (ssc_college) table.
and multiple stream for multiple course how i can add at a time
multiple parent and multiple child id in mysql table.
Note: stream are dependant of course table.

self join with sum field

I have data like this
table t_prod
+---------+----------+-------------+-----------+----------+
|t_prod_id|t_prod_lot|t_prod_sublot|t_prod_card|t_prod_qty|
+---------+----------+-------------+-----------+----------+
| 4 | R001 | 1 | 1 | 6000 |
| 5 | R001 | 1 | 2 | 6000 |
| 6 | R001 | 1 | 3 | 6000 |
| 10 | R001 | 1 | 4 | 6000 |
| 11 | R001 | 1 | 5 | 6000 |
| 12 | R001 | 1 | 6 | 6000 |
| 13 | R001 | 2 | 1 | 6000 |
| 34 | R001 | 2 | 2 | 6000 |
| 36 | R001 | 2 | 3 | 2000 |
+---------+----------+-------------+-----------+----------+
and i want result like this when i select t_prod_lot = R001. count t_prod_sublot when same value and sum t_prod_qty when t_prod_sublot same value
+---------+----------+-------------+-----------+----------+--------------------+---------------+
|t_prod_id|t_prod_lot|t_prod_sublot|t_prod_card|t_prod_qty|count(t_prod_sublot)|sum(t_prod_qty)|
+---------+----------+-------------+-----------+----------+--------------------+---------------+
| 4 | R001 | 1 | 1 | 6000 | 6 | 36000 |
| 5 | R001 | 1 | 2 | 6000 | 6 | 36000 |
| 6 | R001 | 1 | 3 | 6000 | 6 | 36000 |
| 10 | R001 | 1 | 4 | 6000 | 6 | 36000 |
| 11 | R001 | 1 | 5 | 6000 | 6 | 36000 |
| 12 | R001 | 1 | 6 | 6000 | 6 | 36000 |
| 13 | R001 | 2 | 1 | 6000 | 3 | 14000 |
| 34 | R001 | 2 | 2 | 6000 | 3 | 14000 |
| 36 | R001 | 2 | 3 | 2000 | 3 | 14000 |
+---------+----------+-------------+-----------+----------+--------------------+---------------+
what is the query to produce this result ?
Sql Fiddle
Here's one option using a join with a subquery to count and sum the values:
select *
from t_prod t join (
select t_prod_lot, t_prod_sublot,
count(t_prod_card) t_prod_card_cnt,
sum(t_prod_qty) t_prod_qty_sum
from t_prod
group by t_prod_lot, t_prod_sublot
) t2 on t.t_prod_lot = t2.t_prod_lot and t.t_prod_sublot = t2.t_prod_sublot
Updated SQL Fiddle

How to update multiple rows using single where clause

I have a table test and the structure is as shown below
mysql> select * from test;
+----+------------+------------+---------+-----+------+------+
| id | is_deleted | sort_order | version | cid | pid | qid |
+----+------------+------------+---------+-----+------+------+
| 14 | | 6 | 0 | 1 | 2 | 7 |
| 18 | | 1 | 2 | 1 | 4 | 12 |
| 26 | | 9 | 0 | 1 | 1 | 1 |
| 40 | | 1 | 0 | 1 | 5 | 18 |
| 49 | | 2 | 0 | 1 | 5 | 35 |
| 50 | | 3 | 0 | 1 | 5 | 39 |
| 51 | | 4 | 0 | 1 | 5 | 40 |
| 61 | | 10 | 0 | 1 | 1 | 2 |
| 62 | | 11 | 0 | 1 | 1 | 3 |
| 63 | | 12 | 0 | 1 | 1 | 4 |
| 64 | | 13 | 0 | 1 | 1 | 42 |
| 65 | | 14 | 0 | 1 | 1 | 43 |
| 66 | | 2 | 0 | 1 | 4 | 26 |
| 67 | | 3 | 0 | 1 | 4 | 38 |
| 71 | | 7 | 0 | 1 | 2 | 2 |
| 72 | | 8 | 0 | 1 | 2 | 8 |
| 73 | | 9 | 0 | 1 | 2 | 50 |
| 74 | | 10 | 0 | 1 | 2 | 51 |
| 76 | | 3 | 0 | 1 | 3 | 9 |
| 78 | | 4 | 0 | 1 | 3 | 53 |
| 79 | | 1 | 0 | 1 | 6 | 54 |
| 80 | | 1 | 0 | 1 | 11 | 59 |
| 81 | | 1 | 0 | 1 | 12 | 70 |
+----+------------+------------+---------+-----+------+------+
I want to set version to 1 of all the rows whose cid =1,pid not equal to 6,11 and qid not equal to 28,59,54
Can anybody please tell me how to do?
UPDATE test
SET `version` = 1
WHERE cid =1
AND pid NOT in(6,11)
AND qid NOT IN (28,59,54);

How to duplicate row and generate not duplicate ID in mysql

I am using mysql and need to duplicate all row in my table but I do not duplicate id column and new generate number
need ex.
my table
item_db
+------------------------------------------+
| id | name | price | detail |
+------------------------------------------+
| 1 | example | 230 | 3 |
| 2 | power | 110 | 3 |
| 3 | voltage | 1.2 | 4 |
| 4 | example | 240 | 4 |
| 5 | example | 320 | 6 |
| 6 | power | 100 | 4 |
| 7 | power | 110 | 6 |
| 8 | example | 230 | 3 |
| 9 | power | 110 | 3 |
| 10 | voltage | 1.2 | 4 |
| 20 | example | 240 | 4 |
| 21 | example | 320 | 6 |
| 22 | power | 100 | 4 |
| 23 | power | 110 | 6 |
| 24 | example | 240 | 4 |
| 25 | example | 320 | 6 |
| 26 | power | 100 | 4 |
| 27 | power | 110 | 6 |
| 28 | example | 240 | 4 |
| 29 | example | 320 | 6 |
| 30 | power | 100 | 4 |
+------------------------------------------+
i need to duplicate
item_db
+------------------------------------------+
| id | name | price | detail |
+------------------------------------------+
| 1 | example | 230 | 3 |
| 2 | power | 110 | 3 |
| 3 | voltage | 1.2 | 4 |
| 4 | example | 240 | 4 | I need to dup id 1-10 to 101-110
| 5 | example | 320 | 6 |
| 6 | power | 100 | 4 |
| 7 | power | 110 | 6 |
| 8 | example | 230 | 3 |
| 9 | power | 110 | 3 |
| 10 | voltage | 1.2 | 4 |
| 101| example | 230 | 3 |
| 102| power | 110 | 3 |
| 103| voltage | 1.2 | 4 |
| 104| example | 240 | 4 |
| 105| example | 320 | 6 |
| 106| power | 100 | 4 |
| 107| power | 110 | 6 |
| 108| example | 230 | 3 |
| 109| power | 110 | 3 |
| 110| voltage | 1.2 | 4 |
| 20 | example | 240 | 4 |
| 21 | example | 320 | 6 |
| 22 | power | 100 | 4 |
| 23 | power | 110 | 6 |
| 24 | example | 240 | 4 |
| 25 | example | 320 | 6 |
| 26 | power | 100 | 4 | i need to dup 20-30 to 200-210
| 27 | power | 110 | 6 |
| 28 | example | 240 | 4 |
| 29 | example | 320 | 6 |
| 30 | power | 100 | 4 |
| 200| example | 240 | 4 |
| 201| example | 320 | 6 |
| 202| power | 100 | 4 |
| 203| power | 110 | 6 |
| 204| example | 240 | 4 |
| 205| example | 320 | 6 |
| 206| power | 100 | 4 |
| 207| power | 110 | 6 |
| 208| example | 240 | 4 |
| 209| example | 320 | 6 |
| 210| power | 100 | 4 |
+------------------------------------------+
thanks you expert.
You can use INSERT ... SELECT:
INSERT INTO item_db (id, name, price, detail)
SELECT id+180, name, price, detail FROM item_db WHERE id BETWEEN 20 AND 30
How exactly you want to treat id is not entirely clear. If, for example, you wish to automatically assign AUTO_INCREMENT values, then you can (as usual) omit it from the INSERT statement.