So this is what i have
Table : Bill
+------+------------+-----------------+---------------------+
| id | patient_id | bill_number | confirmed_date |
+------+------------+-----------------+---------------------+
| 14 | 32 | 4657 | 2012-07-06 04:11:05 |
| 15 | 33 | 4567 | 2012-07-07 05:11:05 |
| 16 | 34 | 4568 | 2012-07-08 06:11:05 |
| 17 | 35 | 7445 | 2012-08-08 07:11:05 |
+------+------------+-----------------+---------------------+
Table: Claim
+------+---------+------------+-------+--------------+---------------------+
| id | bill_id | patient_id | level | claim_format | confirmed_date |
+------+---------+------------+-------+--------------+---------------------+
| 10 | 14 | 32 | 1 | 1500 | 2012-08-10 10:57:17 |
| 11 | 14 | 32 | 1 | UB04 | 2012-08-10 11:01:42 |
| 12 | 15 | 33 | 1 | 1500 | 2012-09-10 13:57:17 |
| 13 | 15 | 33 | 1 | UB04 | 2012-09-10 12:01:42 |
| 14 | 16 | 34 | 1 | 1500 | 2012-10-10 12:57:17 |
| 15 | 16 | 34 | 1 | UB04 | 2012-10-10 13:01:42 |
| 16 | 17 | 35 | 1 | 1500 | 0012-11-10 15:57:17 |
| 17 | 17 | 35 | 1 | UB04 | 2012-11-10 14:01:42 |
+------+---------+------------+-------+--------------+---------------------+
I want to update the confirmed_date column of bill table with the confirmed_date of claim table after comparing the greater of the two dates for each bill_id(bill_id and patient_id in claims are foreign keys to id and patient_id in bill)
Did i make myself clear enough?
UPDATE Bill b
SET b.confirmed_date = ( SELECT MAX(confirmed_date) FROM Claim c WHERE b.id = c.bill_id)
Related
I have four tables, three of which I need data from, as well as a fourth that stores how this data is associated. When running my query, I'm getting the wrong output and it seems like I'm not linking things up correctly, but I'm unsure as to how to do so. How do I link my joins to get the output I'm looking for?
So far, I've used
SELECT c.class, p.name, s.specialization
FROM players_classes pc
JOIN players p ON p.player_id=pc.player_id
JOIN classes c ON c.class_id=pc.class_id
JOIN specialization s ON s.spec_id=pc.spec_id
which references
CREATE TABLE players(
player_id INT UNSIGNED auto_increment PRIMARY KEY,
name VARCHAR(20)
)...;
CREATE TABLE classes(
class_id INT UNSIGNED auto_increment PRIMARY KEY,
class VARCHAR(20)
)...;
CREATE TABLE specializations(
spec_id INT UNSIGNED auto_increment PRIMARY KEY,
class_id INT UNSIGNED,
specialization VARCHAR(20)
)...;
but I'd like to be using this table in some way to display the information correctly linked, I'm just unsure how to do so:
CREATE TABLE players_classes(
pc_id INT UNSIGNED auto_increment PRIMARY KEY,
FOREIGN KEY(class_id) REFERENCES classes(class_id),
FOREIGN KEY(player_id) REFERENCES players(player_id),
FOREIGN KEY(spec_id) REFERENCES specializations(spec_id)
)...;
I'm expecting to be able to grab a player's name as well as their associated class and specialization, actual results are showing the values associated with 1/1/1 for each id, and so on and so forth.
edit: the data from players_classes is as follows
pc_id | class_id | player_id | spec_id |
1 3 1 8
2 12 2 35
3 2 3 6
etc.
therefore the expected result from this is
class | name | spec
paladin seranul holypa
hunter contherious marksmanship
priest unicorns holypr
I am instead getting
class | name | spec
warlock Affliction Affliction
warlock Grireaver Demonology
warlock Affliction Demonology
and so on throughout the table, listing combinations that do not exist within my players_classes table
specializations table
+---------+----------+----------------+
| spec_id | class_id | specialization |
+---------+----------+----------------+
| 1 | 1 | Affliction |
| 2 | 1 | Destruction |
| 3 | 1 | Demonology |
| 4 | 2 | Shadow |
| 5 | 2 | Discipline |
| 6 | 2 | HolyPr |
| 7 | 3 | Retribution |
| 8 | 3 | HolyPa |
| 9 | 3 | ProtectionPa |
| 10 | 4 | ProtectionWa |
| 11 | 4 | Arms |
| 12 | 4 | Fury |
| 13 | 5 | FrostMa |
| 14 | 5 | Fire |
| 15 | 5 | Arcane |
| 16 | 6 | vengeance |
| 17 | 6 | havoc |
| 18 | 7 | guardian |
| 19 | 7 | balance |
| 20 | 7 | feral |
| 21 | 7 | restorationDr |
| 22 | 8 | elemental |
| 23 | 8 | enhance |
| 24 | 8 | restorationSh |
| 25 | 9 | frostDk |
| 26 | 9 | blood |
| 27 | 9 | unholy |
| 28 | 10 | outlaw |
| 29 | 10 | assassin |
| 30 | 10 | subtlety |
| 31 | 11 | brewmaster |
| 32 | 11 | windwalker |
| 33 | 11 | mistweaver |
| 34 | 12 | BeastMaster |
| 35 | 12 | marksmanship |
| 36 | 12 | Survival |
+---------+----------+----------------+
classes table
+----------+-------------+
| class_id | class |
+----------+-------------+
| 1 | warlock |
| 2 | priest |
| 3 | paladin |
| 4 | warrior |
| 5 | mage |
| 6 | demonhunter |
| 7 | druid |
| 8 | shaman |
| 9 | deathknight |
| 10 | rogue |
| 11 | monk |
| 12 | hunter |
+----------+-------------+
players table
+-----------+--------------+
| player_id | name |
+-----------+--------------+
| 1 | Seranul |
| 2 | Contherious |
| 3 | Unicorns |
| 4 | Remereili |
| 5 | Affliction |
| 6 | Meowing |
| 7 | Brobot |
| 8 | Bagelsbbq |
| 9 | Rafusen |
| 10 | Taiboku |
| 11 | Yikes |
| 12 | Thunderblaze |
| 13 | Muo |
| 14 | Intz |
| 15 | Trunks |
| 16 | Kalphyte |
| 17 | Eyeoftheshoe |
| 18 | Amuhnet |
| 19 | Synkka |
| 20 | Affliction |
| 21 | Kts |
| 22 | Shadowdreams |
| 23 | Zahel |
| 24 | Azrama |
| 25 | Seranul |
| 26 | Momspaghetti |
| 27 | Ohki |
| 28 | Rafusen |
| 29 | Cindyy |
| 30 | Grireaver |
| 31 | Intz |
| 32 | lazy |
| 33 | missworld |
| 34 | Affliction |
| 35 | Amuhnet |
| 36 | eyeoftheshoe |
| 37 | sanctus |
| 38 | nozshelen |
| 39 | Contherious |
| 40 | messer |
| 41 | catathor |
| 42 | demonblaze |
| 43 | wrillett |
| 44 | raagnnar |
| 45 | xizi |
| 46 | nemesix |
| 47 | zeroskill |
| 48 | chikfillidan |
| 49 | tentenlol |
| 50 | unicorns |
| 51 | bubuhtide |
| 52 | ohki |
| 53 | azrama |
+-----------+--------------+
players_classes table
+-------+----------+-----------+---------+
| pc_id | class_id | player_id | spec_id |
+-------+----------+-----------+---------+
| 1 | 3 | 1 | 8 |
| 2 | 12 | 2 | 35 |
| 3 | 2 | 3 | 6 |
| 4 | 11 | 4 | 31 |
| 5 | 1 | 5 | 1 |
| 6 | 12 | 6 | 34 |
| 7 | 2 | 7 | 6 |
| 8 | 11 | 8 | 31 |
| 9 | 2 | 9 | 6 |
| 10 | 7 | 10 | 21 |
| 11 | 4 | 11 | 11 |
| 12 | 8 | 12 | 22 |
| 13 | 4 | 13 | 12 |
| 14 | 5 | 14 | 13 |
| 15 | 3 | 15 | 7 |
| 16 | 11 | 16 | 33 |
| 17 | 8 | 17 | 22 |
| 18 | 2 | 18 | 6 |
| 19 | 8 | 19 | 23 |
| 20 | 11 | 20 | 33 |
| 21 | 5 | 21 | 13 |
| 22 | 6 | 22 | 17 |
| 23 | 10 | 23 | 29 |
| 24 | 8 | 24 | 22 |
| 25 | 11 | 25 | 31 |
| 26 | 11 | 26 | 32 |
| 27 | 4 | 27 | 11 |
| 28 | 5 | 28 | 13 |
| 29 | 7 | 29 | 19 |
| 30 | 1 | 30 | 3 |
| 31 | 9 | 31 | 25 |
| 32 | 3 | 32 | 8 |
| 33 | 9 | 33 | 25 |
| 34 | 1 | 34 | 3 |
| 35 | 2 | 35 | 6 |
| 36 | 4 | 36 | 11 |
| 37 | 5 | 37 | 13 |
| 38 | 5 | 38 | 13 |
| 39 | 9 | 39 | 25 |
| 40 | 6 | 40 | 17 |
| 41 | 10 | 41 | 28 |
| 42 | 2 | 42 | 6 |
| 43 | 8 | 43 | 24 |
+-------+----------+-----------+---------+
You need to use the relationship table in your query:
SELECT c.class, p.name, s.specialization
FROM players_classes pc
JOIN players p ON p.player_id = pc.player_id
JOIN classes c ON c.class_id = pc.class_id
JOIN specializations s ON s.spec_id = pc.spec_id
DEMO
You shouldn't even have class_id and spec_id in the other tables, since these are many-to-many relationships, and those columns can only be used for one-to-one relationships.
i have two tables called
1 table smartpos.pos_order_Id
+---------+--------------+---------+--------+--------------+----------------+------------+
| orderId | restaurantId | tableId | closed | customerName | customerNumber | dateorderd |
+---------+--------------+---------+--------+--------------+----------------+------------+
| 7 | 14 | 0 | yes | | | 21/03/2018 |
| 8 | 14 | 0 | yes | | | 21/03/2018 |
| 9 | 14 | 0 | no | | | 20/03/2018 |
| 10 | 14 | 0 | yes | soumya | 1234567890 | 21/03/2018 |
| 11 | 14 | 0 | yes | | | 21/03/2018 |
| 12 | 14 | 0 | yes | | | 21/03/2018 |
| 13 | 14 | 0 | yes | | | 21/03/2018 |
| 14 | 14 | 0 | yes | | | 20/03/2018 |
| 15 | 14 | 0 | no | | | 22/03/2018 |
+---------+--------------+---------+--------+--------------+----------------+------------+
2smartpos.pos_invoice
+---------------+---------+----------+-------------+-------------+------------+-------------+---------------+
| invoiceNumber | orderId | totalAmt | discountAmt | totalTaxAmt | grandTotal | paymentmode | paymentrefNum |
+---------------+---------+----------+-------------+-------------+------------+-------------+---------------+
| 1 | 7 | 200 | 34 | 46 | 212 | Cash | |
| 2 | 10 | 1200 | 200 | 280 | 1280 | Cash | |
| 3 | 1 | 720 | 34 | 120 | 806 | Cash | |
| 4 | 12 | 240 | 34 | 58 | 264 | Cash | |
| 5 | 13 | 330 | 32 | 83 | 381 | Cash | |
| 6 | 14 | 80 | 2 | 22 | 100 | Cash | |
+---------------+---------+----------+-------------+-------------+------------+-------------+---------------+
i want to fetch invoice details using restaurantId and two dates by providing restaurantId and dates as follows
select inv.invoiceNumber ,inv.totalAmt,inv.discountAmt,inv.totalTaxAmt,inv.grandTotal,i.dateorderd from smartpos.pos_invoice inv,smartpos.pos_order_Id i where inv.invoiceNumber in (select invv.invoiceNumber from smartpos.pos_invoice invv where invv.orderId in(select ii.orderId from smartpos.pos_order_Id ii where ii.closed='yes' and ii.restaurantId=14 and STR_TO_DATE(dateorderd,'%d/%m/%Y') between STR_TO_DATE('20/03/2018','%d/%m/%Y') and STR_TO_DATE('21/03/2018','%d/%m/%Y'))) group by inv.invoiceNumber ;
out put:
+---------------+----------+-------------+-------------+------------+------------+
| invoiceNumber | totalAmt | discountAmt | totalTaxAmt | grandTotal | dateorderd |
+---------------+----------+-------------+-------------+------------+------------+
| 1 | 200 | 34 | 46 | 212 | NULL |
| 2 | 1200 | 200 | 280 | 1280 | NULL |
| 4 | 240 | 34 | 58 | 264 | NULL |
| 5 | 330 | 32 | 83 | 381 | NULL |
| 6 | 80 | 2 | 22 | 100 | NULL |
+---------------+----------+-------------+-------------+------------+------------+
but when i run above query it gives null values , how to fetch the date as well?
Its difficult to understand what you wrote but i think you query is much simple than it seems, try to use this approach :
select
inv.invoiceNumber ,
inv.totalAmt,
inv.discountAmt,
inv.totalTaxAmt,
inv.grandTotal,
i.dateorderd
from
smartpos.pos_invoice inv,
smartpos.pos_order_Id i
where
inv.orderId = i.orderId
and
i.closed='yes'
and
i.restaurantId=14
and
STR_TO_DATE(dateorderd,'%d/%m/%Y') between STR_TO_DATE('20/03/2018','%d/%m/%Y') and STR_TO_DATE('21/03/2018','%d/%m/%Y')
group by
inv.invoiceNumber;
by followed Mysql query to dynamically convert rows to columns on the basis of two columns,
I have 4 table to convert dinamiacally rows into columns as RESULT
TABLE A
| id | stages |
-----+----------
| 1 | Stage A |
| 2 | Stage B |
| 3 | Stage C |
TABLE B
| id_b | code | lessons |
-------+------+--------------
| 10 | FIS | Physics |
| 11 | MAT | Mathematics |
| 12 | KIM | Chemistry |
| 13 | BIO | Biology |
TABLE C
|id_c| students |
-----+-------------
| 20 | student 20 |
| 21 | student 21 |
| 22 | student 22 |
| 23 | student 23 |
| 24 | student 24 |
| 25 | student 25 |
| 26 | student 26 |
| 27 | student 27 |
TABLE D
| id_d | id_a | id_b | id_c | value_m | value_n |
-------+------+------+------+---------+----------
| 201 | 1 | 11 | 20 | 71 | 73 |
| 203 | 1 | 13 | 20 | 80 | 87 |
| 204 | 2 | 10 | 21 | 72 | 75 |
| 206 | 2 | 13 | 21 | 76 | 78 |
| 208 | 2 | 12 | 22 | 72 | 78 |
| 209 | 2 | 13 | 22 | 76 | 80 |
| 210 | 3 | 11 | 23 | 73 | 71 |
| 211 | 3 | 12 | 23 | 71 | 77 |
| 212 | 3 | 13 | 23 | 78 | 81 |
| 213 | 3 | 10 | 24 | 70 | 81 |
| 214 | 3 | 11 | 25 | 71 | 82 |
| 215 | 3 | 12 | 26 | 74 | 83 |
| 215 | 3 | 13 | 27 | 78 | 80 |
RESULT
| students | FIS_1 | MAT_1 | KIM_1 | BIO_1 | FIS_2 | MAT_2 | KIM_2 | BIO_2 | FIS_3 | MAT_3 | KIM_3 | BIO_3 |
-------------+-------+-------+-------+-------+--------+------+-------+-------+-------+-------+-------+--------
| student 20 | | 71,73 | | 80,87 | | | | | | | | |
| student 21 | | | | | 72,75 | 76,78 | | | | | | |
| student 22 | | | | | | | 72,78 | 76,80 | | | | |
| student 23 | | | | | | | | | | 73,71 | 71,77 | 78,81 |
| student 24 | | | | | | | | | 70,81 | | | |
| student 25 | | | | | | | | | | 71,82 | | |
| student 26 | | | | | | | | | | | 74,83 | |
| student 27 | | | | | | | | | | | | 78,80 |
Where FIS_1, MAT_1,... FIS_2, MAT_2.., FIS_3, MAT_3.. is CONCAT from TABLE B kode and TABLE A id,
and value MAT_1, BIO_1... is CONCAT from TABLE D value_m and value_n
It's Posible? How can I do that with GROUP_CONCAT mysql query? I've tried it but still not successful..
Thanks for your advance..
I have three tables, mess_stock, mess_voucher, add_grocery.
Mess_stock table is below,
+-----+------------+-----------------+-----------------+--------+---------+---------+------------+----------+
| sno | voucher_id | particular_name | opening_balance | inward | outward | balance | pay_amount | pay_type |
+-----+------------+-----------------+-----------------+--------+---------+---------+------------+----------+
| 49 | 5 | 4 | 100 | 10 | 100 | 10 | 10.00 | 1 |
| 50 | 17 | 5 | 111 | 10 | 20 | 101 | 60.00 | 1 |
| 51 | 7 | 3 | 123 | 2 | 1 | 124 | 300.00 | 1 |
| 52 | 7 | 1 | 123 | 20 | 20 | 123 | 500.00 | 2 |
| 53 | 14 | 8 | 100 | 5 | 95 | 10 | 60.00 | 2 |
+-----+------------+-----------------+-----------------+--------+---------+---------+------------+----------+
Mess_voucher table is below
+------------+--------------+--------------+
| voucher_id | voucher_name | voucher_date |
+------------+--------------+--------------+
| 5 | VG1001 | 2015-02-19 |
| 6 | VG1001 | 2015-02-20 |
| 7 | VG1002 | 2015-02-20 |
| 8 | VG1002 | 2015-02-19 |
| 9 | MS1001 | 2015-02-20 |
| 10 | VG10012 | 2015-02-19 |
| 11 | 0 | 2015-02-23 |
| 12 | 1 | 2015-02-24 |
| 13 | MS1001 | 2015-02-25 |
| 14 | MS1001 | 2015-02-28 |
| 15 | VG1003 | 2015-02-28 |
| 16 | MS1001 | 2015-02-19 |
| 17 | MS1001 | 2015-02-21 |
+------------+--------------+--------------+
Add_grocery table is below
+-----+-----------------+------------------+
| sno | particular_name | particular_price |
+-----+-----------------+------------------+
| 1 | Rice | 25.00 |
| 3 | Mango | 150.00 |
| 4 | Coconut | 22.00 |
| 5 | Banana | 6.00 |
| 6 | Raddish | 12.00 |
| 7 | Apple | 150.00 |
| 8 | Pumkin | 12.00 |
+-----+-----------------+------------------+
I want to group the sum of pay_amount of mess_stock table. I have used the below query
SELECT opening_balance AS ope_stock,
balance AS clo_stock,
SUM(IF(pay_type = 1, pay_amount, 0)) mess_pay,
SUM(IF(pay_type=2, pay_amount, 0)) est_pay
FROM mess_stock;
That works fine. The particular_name is the auto increment id of add_grocery table. I need the inward outward amount total. For example the inward amount 10 means it has to get the particular_price from add_grocery using the particular_name provided in the mess_stock table, similarly I need all the answer. And I want to sort that by date wise. The date of the entry is stored in the mess_voucher table that is connected to mess_stock table.
Try this it will work :
Use Inner Join :
SELECT t2.`particular_name`,t1.`inward`,t1.`outward`,t2.`particular_price`,t3.`voucher_date` from Mess_stock t1 JOIN Add_grocery t2 ON t1.`particular_name`=t2.`sno` JOIN Mess_voucher t3 ON t3.`voucher_id`=t1.`voucher_id` ORDER BY t3.`voucher_date` DESC
I have 3 tables in my db, the scenario is inventory is entered into the database with reference to invoice no/po number, then users request for inventory and admin assign the items from specific invoices_items/po_items.
I need query to get when an invoice number is entered into the database and what quantity of items is this invoice has. then when when admin issue items from this issue. in other words i have to tracked inventory transactions with reference to invoice/po number.
I have following structure of tables,
table - po_reference
+----------------+-------------------------+--------------------+--------+---------------------+
| po_refrence_id | po_reference_name | requested_quantity | cost | created_on |
+----------------+-------------------------+--------------------+--------+---------------------+
| 6 | Dell Computer 000001256 | 14 | 15000 | 2015-02-18 10:36:33 |
| 11 | Dell Computer 000001257 | 50 | 150000 | 2015-02-18 10:38:33 |
+----------------+-------------------------+--------------------+--------+---------------------+
table - po_reference_details
+-------------------------+----------------+--------------------+-------------------+----------------------+-----------------------+
| po_reference_details_id | po_refrence_id | quantity_requested | quantity_received | quantity_outstanding | remarks |
+-------------------------+----------------+--------------------+-------------------+----------------------+-----------------------+
| 6 | 6 | 20 | 14 | 6 | 6 items are short.... |
| 8 | 11 | 60 | 50 | 10 | 10 items are short... |
+-------------------------+----------------+--------------------+-------------------+----------------------+-----------------------+
table - stock
+----------+----------+---------------------+------------+---------------------+------------+-----------+---------+--------------+---------+-------------+----------------+------------------+
| stock_id | quantity | created_on | created_by | updated_on | updated_by | module_id | item_id | main_unit_id | unit_id | category_id | po_refrence_id | startup_quantity |
+----------+----------+---------------------+------------+---------------------+------------+-----------+---------+--------------+---------+-------------+----------------+------------------+
| 290 | 35 | 2015-02-18 02:15:00 | NULL | NULL | NULL | 1 | 286 | 94 | 24 | 47 | 6 | 50 |
| 291 | 110 | 2015-02-18 00:00:00 | NULL | 2015-02-18 00:00:00 | NULL | 2 | 286 | 94 | 24 | 47 | 6 | 10 |
+----------+----------+---------------------+------------+---------------------+------------+-----------+---------+--------------+---------+-------------+----------------+------------------+
and request_stock_bridge
+--------------------------+------------+----------------+------------------+---------------------+--------------------------------------------------------------------+-----------------+--------------+
| stock_requests_bridge_id | request_id | po_refrence_id | quantity_on_hand | issued_date | remarks | issued_quantity | main_unit_id |
+--------------------------+------------+----------------+------------------+---------------------+--------------------------------------------------------------------+-----------------+--------------+
| 8 | 78 | 6 | 44 | 2015-02-18 06:49:34 | items are short , giving you 2 less, request after a week again... | 6 | 94 |
| 9 | 79 | 6 | 42 | 2015-02-18 08:18:56 | test | 2 | 94 |
| 10 | 80 | 6 | 35 | 2015-02-18 08:56:39 | 2 shorts.... | 7 | 94 |
+--------------------------+------------+----------------+------------------+---------------------+--------------------------------------------------------------------+-----------------+--------------+
and finally table - request
+------------+---------------+--------------------+---------------------+-----------------+--------+---------------+-----------+---------+
| request_id | department_id | quantity_requested | requested_date | quantity_issued | status | employee_name | module_id | item_id |
+------------+---------------+--------------------+---------------------+-----------------+--------+---------------+-----------+---------+
| 76 | 54 | 8 | 2015-02-18 00:00:00 | 0 | 0 | MTaqi | 2 | 279 |
| 77 | 54 | 7 | 2015-02-18 00:00:00 | 0 | 0 | MTaqi | 2 | 279 |
| 78 | 54 | 8 | 2015-02-18 00:00:00 | 0 | 1 | MTaqi | 2 | 286 |
| 79 | 54 | 2 | 2015-02-18 00:00:00 | 0 | 1 | MTaqi | 2 | 286 |
| 80 | 54 | 9 | 2015-02-18 00:00:00 | 0 | 1 | MTaqi | 2 | 286 |
+------------+---------------+--------------------+---------------------+-----------------+--------+---------------+-----------+---------+
i have write this query but doesn't work,
SELECT s.created_on, po.po_reference_name, s.startup_quantity, su.issued_date, su.issued_quantity, su.quantity_on_hand, su.remarks,po.po_refrence_id
FROM stock s, po_reference po, request r, stock_requests_bridge su
WHERE po.po_refrence_id = s.po_refrence_id
AND su.po_refrence_id = s.po_refrence_id
AND s.item_id = 286
GROUP by po.po_refrence_id
it returns this,
+---------------------+-------------------------+------------------+---------------------+-----------------+------------------+--------------------------------------------------------------------+----------------+
| created_on | po_reference_name | startup_quantity | issued_date | issued_quantity | quantity_on_hand | remarks | po_refrence_id |
+---------------------+-------------------------+------------------+---------------------+-----------------+------------------+--------------------------------------------------------------------+----------------+
| 2015-02-18 02:15:00 | Dell Computer 000001256 | 50 | 2015-02-18 06:49:34 | 6 | 44 | items are short , giving you 2 less, request after a week again... | 6 |
+---------------------+-------------------------+------------------+---------------------+-----------------+------------------+--------------------------------------------------------------------+----------------+