Order Quantity Double after joining with delivery












0














We can have multiple deliveries for single order item. So,when I am joining Order-Item with Delivery, I get multiple rows. Now, if I want to get order quantity at Order Item level ( not including Delivery-Item), I get wrong aggregation. I understand why query is behaving like that , but not sure how to make aggregation correct at each possible level of drill down .



Order Table



Deliver Table



After joining Order and Deliv



Result is Correct at Order ID,Item, Product level.










share|improve this question
























  • At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
    – SQL_NOVICE
    Nov 12 at 16:40










  • You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
    – scaisEdge
    Nov 12 at 16:49






  • 1




    there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
    – Hogan
    Nov 12 at 16:49










  • I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
    – SQL_NOVICE
    Nov 12 at 17:14










  • I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
    – Austin Mullins
    Nov 12 at 18:35
















0














We can have multiple deliveries for single order item. So,when I am joining Order-Item with Delivery, I get multiple rows. Now, if I want to get order quantity at Order Item level ( not including Delivery-Item), I get wrong aggregation. I understand why query is behaving like that , but not sure how to make aggregation correct at each possible level of drill down .



Order Table



Deliver Table



After joining Order and Deliv



Result is Correct at Order ID,Item, Product level.










share|improve this question
























  • At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
    – SQL_NOVICE
    Nov 12 at 16:40










  • You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
    – scaisEdge
    Nov 12 at 16:49






  • 1




    there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
    – Hogan
    Nov 12 at 16:49










  • I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
    – SQL_NOVICE
    Nov 12 at 17:14










  • I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
    – Austin Mullins
    Nov 12 at 18:35














0












0








0







We can have multiple deliveries for single order item. So,when I am joining Order-Item with Delivery, I get multiple rows. Now, if I want to get order quantity at Order Item level ( not including Delivery-Item), I get wrong aggregation. I understand why query is behaving like that , but not sure how to make aggregation correct at each possible level of drill down .



Order Table



Deliver Table



After joining Order and Deliv



Result is Correct at Order ID,Item, Product level.










share|improve this question















We can have multiple deliveries for single order item. So,when I am joining Order-Item with Delivery, I get multiple rows. Now, if I want to get order quantity at Order Item level ( not including Delivery-Item), I get wrong aggregation. I understand why query is behaving like that , but not sure how to make aggregation correct at each possible level of drill down .



Order Table



Deliver Table



After joining Order and Deliv



Result is Correct at Order ID,Item, Product level.







sql hana sql-scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 17:17

























asked Nov 12 at 16:37









SQL_NOVICE

817




817












  • At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
    – SQL_NOVICE
    Nov 12 at 16:40










  • You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
    – scaisEdge
    Nov 12 at 16:49






  • 1




    there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
    – Hogan
    Nov 12 at 16:49










  • I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
    – SQL_NOVICE
    Nov 12 at 17:14










  • I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
    – Austin Mullins
    Nov 12 at 18:35


















  • At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
    – SQL_NOVICE
    Nov 12 at 16:40










  • You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
    – scaisEdge
    Nov 12 at 16:49






  • 1




    there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
    – Hogan
    Nov 12 at 16:49










  • I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
    – SQL_NOVICE
    Nov 12 at 17:14










  • I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
    – Austin Mullins
    Nov 12 at 18:35
















At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
– SQL_NOVICE
Nov 12 at 16:40




At Order ID, Order Item, Prod level it is working fine .. But Only product level gives me wrong sum ..
– SQL_NOVICE
Nov 12 at 16:40












You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
– scaisEdge
Nov 12 at 16:49




You should add text table schema .. data sample, actual result and expected result .. (not links to image only)
– scaisEdge
Nov 12 at 16:49




1




1




there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
– Hogan
Nov 12 at 16:49




there is no way to understand what you want. Please provide expected output along with sample data and query tried -- use text not pictures.
– Hogan
Nov 12 at 16:49












I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
– SQL_NOVICE
Nov 12 at 17:14




I tried to attach Sample Table , Query and Expected Result , but it is going as link ..
– SQL_NOVICE
Nov 12 at 17:14












I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
– Austin Mullins
Nov 12 at 18:35




I don't understand what you want aggregated, and I don't understand what you mean when you say it's wrong.
– Austin Mullins
Nov 12 at 18:35












2 Answers
2






active

oldest

votes


















0














this is how I would approach this problem. From the looks of things your table does not look normalised to me. You have ORD_ID and ORD_ITM present in two tables. You should have this present only in you T_ORDER table then have the ORD_ITM present in your T_DELIV table. From the diagram you have also shown, you do not have an OrderItem_table so it will be confusing to help. But with my solution, just have your ORD_ITM only as a foreign key in your delivery table then join by this field. Hope this helps.






share|improve this answer





















  • It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
    – Austin Mullins
    Nov 12 at 18:36










  • @AustinMullins denormalization is a common solution for performance problems, especially on column store
    – András
    Nov 13 at 8:41



















0














There is a problem with data you have provided



The product for Order 10001 item 30 is P2 in one table and P3 in the other



Could you please provide your sample data and table structure in the following format so others can help you easily



create column table T_ORDER (
ORD_ID int,
ORD_ITM int,
PROD varchar(5),
ORD_QTY int
);

create column table T_DELIV (
DELIV_ID int,
DELIV_ITM int,
ORD_ID int,
ORD_ITM int,
DELIV_QTY int,
PROD varchar(5)
);

insert into T_ORDER values (10001,10,'P1',50);
insert into T_ORDER values (10001,20,'P1',60);
insert into T_ORDER values (10001,30,'P2',40);
insert into T_ORDER values (10001,40,'P3',30);
insert into T_ORDER values (10002,50,'P4',20);


insert into T_DELIV values (50001,10,10001,10,20,'P1');
insert into T_DELIV values (50001,20,10001,10,30,'P1');
insert into T_DELIV values (50002,10,10001,20,60,'P2');
insert into T_DELIV values (50002,20,10001,30,30,'P3');
insert into T_DELIV values (50003,10,10001,40,10,'P3');
insert into T_DELIV values (50003,20,10001,40,15,'P3');





share|improve this answer





















  • @ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
    – SQL_NOVICE
    Nov 14 at 4:39












  • Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
    – Eralper
    Nov 15 at 6:52










  • Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
    – SQL_NOVICE
    Nov 15 at 16:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266461%2forder-quantity-double-after-joining-with-delivery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














this is how I would approach this problem. From the looks of things your table does not look normalised to me. You have ORD_ID and ORD_ITM present in two tables. You should have this present only in you T_ORDER table then have the ORD_ITM present in your T_DELIV table. From the diagram you have also shown, you do not have an OrderItem_table so it will be confusing to help. But with my solution, just have your ORD_ITM only as a foreign key in your delivery table then join by this field. Hope this helps.






share|improve this answer





















  • It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
    – Austin Mullins
    Nov 12 at 18:36










  • @AustinMullins denormalization is a common solution for performance problems, especially on column store
    – András
    Nov 13 at 8:41
















0














this is how I would approach this problem. From the looks of things your table does not look normalised to me. You have ORD_ID and ORD_ITM present in two tables. You should have this present only in you T_ORDER table then have the ORD_ITM present in your T_DELIV table. From the diagram you have also shown, you do not have an OrderItem_table so it will be confusing to help. But with my solution, just have your ORD_ITM only as a foreign key in your delivery table then join by this field. Hope this helps.






share|improve this answer





















  • It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
    – Austin Mullins
    Nov 12 at 18:36










  • @AustinMullins denormalization is a common solution for performance problems, especially on column store
    – András
    Nov 13 at 8:41














0












0








0






this is how I would approach this problem. From the looks of things your table does not look normalised to me. You have ORD_ID and ORD_ITM present in two tables. You should have this present only in you T_ORDER table then have the ORD_ITM present in your T_DELIV table. From the diagram you have also shown, you do not have an OrderItem_table so it will be confusing to help. But with my solution, just have your ORD_ITM only as a foreign key in your delivery table then join by this field. Hope this helps.






share|improve this answer












this is how I would approach this problem. From the looks of things your table does not look normalised to me. You have ORD_ID and ORD_ITM present in two tables. You should have this present only in you T_ORDER table then have the ORD_ITM present in your T_DELIV table. From the diagram you have also shown, you do not have an OrderItem_table so it will be confusing to help. But with my solution, just have your ORD_ITM only as a foreign key in your delivery table then join by this field. Hope this helps.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 17:16









Ted

302




302












  • It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
    – Austin Mullins
    Nov 12 at 18:36










  • @AustinMullins denormalization is a common solution for performance problems, especially on column store
    – András
    Nov 13 at 8:41


















  • It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
    – Austin Mullins
    Nov 12 at 18:36










  • @AustinMullins denormalization is a common solution for performance problems, especially on column store
    – András
    Nov 13 at 8:41
















It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
– Austin Mullins
Nov 12 at 18:36




It is nice to have a normalized database, but I don't think that is preventing this join from working (for now).
– Austin Mullins
Nov 12 at 18:36












@AustinMullins denormalization is a common solution for performance problems, especially on column store
– András
Nov 13 at 8:41




@AustinMullins denormalization is a common solution for performance problems, especially on column store
– András
Nov 13 at 8:41













0














There is a problem with data you have provided



The product for Order 10001 item 30 is P2 in one table and P3 in the other



Could you please provide your sample data and table structure in the following format so others can help you easily



create column table T_ORDER (
ORD_ID int,
ORD_ITM int,
PROD varchar(5),
ORD_QTY int
);

create column table T_DELIV (
DELIV_ID int,
DELIV_ITM int,
ORD_ID int,
ORD_ITM int,
DELIV_QTY int,
PROD varchar(5)
);

insert into T_ORDER values (10001,10,'P1',50);
insert into T_ORDER values (10001,20,'P1',60);
insert into T_ORDER values (10001,30,'P2',40);
insert into T_ORDER values (10001,40,'P3',30);
insert into T_ORDER values (10002,50,'P4',20);


insert into T_DELIV values (50001,10,10001,10,20,'P1');
insert into T_DELIV values (50001,20,10001,10,30,'P1');
insert into T_DELIV values (50002,10,10001,20,60,'P2');
insert into T_DELIV values (50002,20,10001,30,30,'P3');
insert into T_DELIV values (50003,10,10001,40,10,'P3');
insert into T_DELIV values (50003,20,10001,40,15,'P3');





share|improve this answer





















  • @ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
    – SQL_NOVICE
    Nov 14 at 4:39












  • Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
    – Eralper
    Nov 15 at 6:52










  • Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
    – SQL_NOVICE
    Nov 15 at 16:26
















0














There is a problem with data you have provided



The product for Order 10001 item 30 is P2 in one table and P3 in the other



Could you please provide your sample data and table structure in the following format so others can help you easily



create column table T_ORDER (
ORD_ID int,
ORD_ITM int,
PROD varchar(5),
ORD_QTY int
);

create column table T_DELIV (
DELIV_ID int,
DELIV_ITM int,
ORD_ID int,
ORD_ITM int,
DELIV_QTY int,
PROD varchar(5)
);

insert into T_ORDER values (10001,10,'P1',50);
insert into T_ORDER values (10001,20,'P1',60);
insert into T_ORDER values (10001,30,'P2',40);
insert into T_ORDER values (10001,40,'P3',30);
insert into T_ORDER values (10002,50,'P4',20);


insert into T_DELIV values (50001,10,10001,10,20,'P1');
insert into T_DELIV values (50001,20,10001,10,30,'P1');
insert into T_DELIV values (50002,10,10001,20,60,'P2');
insert into T_DELIV values (50002,20,10001,30,30,'P3');
insert into T_DELIV values (50003,10,10001,40,10,'P3');
insert into T_DELIV values (50003,20,10001,40,15,'P3');





share|improve this answer





















  • @ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
    – SQL_NOVICE
    Nov 14 at 4:39












  • Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
    – Eralper
    Nov 15 at 6:52










  • Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
    – SQL_NOVICE
    Nov 15 at 16:26














0












0








0






There is a problem with data you have provided



The product for Order 10001 item 30 is P2 in one table and P3 in the other



Could you please provide your sample data and table structure in the following format so others can help you easily



create column table T_ORDER (
ORD_ID int,
ORD_ITM int,
PROD varchar(5),
ORD_QTY int
);

create column table T_DELIV (
DELIV_ID int,
DELIV_ITM int,
ORD_ID int,
ORD_ITM int,
DELIV_QTY int,
PROD varchar(5)
);

insert into T_ORDER values (10001,10,'P1',50);
insert into T_ORDER values (10001,20,'P1',60);
insert into T_ORDER values (10001,30,'P2',40);
insert into T_ORDER values (10001,40,'P3',30);
insert into T_ORDER values (10002,50,'P4',20);


insert into T_DELIV values (50001,10,10001,10,20,'P1');
insert into T_DELIV values (50001,20,10001,10,30,'P1');
insert into T_DELIV values (50002,10,10001,20,60,'P2');
insert into T_DELIV values (50002,20,10001,30,30,'P3');
insert into T_DELIV values (50003,10,10001,40,10,'P3');
insert into T_DELIV values (50003,20,10001,40,15,'P3');





share|improve this answer












There is a problem with data you have provided



The product for Order 10001 item 30 is P2 in one table and P3 in the other



Could you please provide your sample data and table structure in the following format so others can help you easily



create column table T_ORDER (
ORD_ID int,
ORD_ITM int,
PROD varchar(5),
ORD_QTY int
);

create column table T_DELIV (
DELIV_ID int,
DELIV_ITM int,
ORD_ID int,
ORD_ITM int,
DELIV_QTY int,
PROD varchar(5)
);

insert into T_ORDER values (10001,10,'P1',50);
insert into T_ORDER values (10001,20,'P1',60);
insert into T_ORDER values (10001,30,'P2',40);
insert into T_ORDER values (10001,40,'P3',30);
insert into T_ORDER values (10002,50,'P4',20);


insert into T_DELIV values (50001,10,10001,10,20,'P1');
insert into T_DELIV values (50001,20,10001,10,30,'P1');
insert into T_DELIV values (50002,10,10001,20,60,'P2');
insert into T_DELIV values (50002,20,10001,30,30,'P3');
insert into T_DELIV values (50003,10,10001,40,10,'P3');
insert into T_DELIV values (50003,20,10001,40,15,'P3');






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 at 6:59









Eralper

5,04511220




5,04511220












  • @ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
    – SQL_NOVICE
    Nov 14 at 4:39












  • Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
    – Eralper
    Nov 15 at 6:52










  • Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
    – SQL_NOVICE
    Nov 15 at 16:26


















  • @ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
    – SQL_NOVICE
    Nov 14 at 4:39












  • Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
    – Eralper
    Nov 15 at 6:52










  • Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
    – SQL_NOVICE
    Nov 15 at 16:26
















@ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
– SQL_NOVICE
Nov 14 at 4:39






@ Eralper ...you are correct. Delivery Table has issue with Product value . That is redundant information though , so should not affect final result. Basically , I am trying to build a HANA calculation view but unable to get right aggregation at every level of drill down possible.
– SQL_NOVICE
Nov 14 at 4:39














Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
– Eralper
Nov 15 at 6:52




Please provide sample data with above INSERT commands, so many developers here in the forum will be willing to help you with a solution asap
– Eralper
Nov 15 at 6:52












Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
– SQL_NOVICE
Nov 15 at 16:26




Eralper- Inserts statement provided by you works perfect for generating example data. I was able to resolve it by adding Order Quantity from Order table again to the result set of Order-Deliv join. Only thing I had to do is to put Order_ID and Order_ITM in "group by" no matter whatever fields user selects in the final query . They way to do it in HANA modeling is to use "Keep Flag" . Thanks for all the help .
– SQL_NOVICE
Nov 15 at 16:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266461%2forder-quantity-double-after-joining-with-delivery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly