can someone please help me getting the correct SQL statement, I added a picture of the example and I need some help using the sql statements as a beginner..
I want the result to show exactly the same in a gridview..I attached a picture to explain..
appreciate any help guys!
I hope this helps you. I do not have a reputation to comment on Stack Overflow right now, hence posting as answer. Also, please post the table names, it helps to write query easily.
I have named the first table as ORDER, second as ORDER_SUMMARY and third as MODEL. Let me know if this solves your query.
SELECT O.CUSTOMER_NAME,
O.CUSTOMER_ADDRESS,
O.DATE_OF_PURCHASE,
O.ORDER_BY,
O.ORDER_NUMBER,
O.PALLET_NUMBER,
M.SERIAL_NUMBER,
OS.PIECE_PRICE
FROM ORDER O
JOIN ORDER_SUMMARY OS ON O.ORDER_NUMBER = OS.ORDER_NUMBER
JOIN MODEL M ON M.PALLET_NUMBER = OS.PALLET_NUMBER;
Related
I hope you're well.
I've been toying with an SQL query recently but there's a column that is supposed to be the result of an arithmetic operation that does not seem to work for me. Here is the code I'm using:
select activecampaign.campaign_step,
count(activecampaign.email_name) as email_opened,
count(contracts.uuid) as contracts,
count(contracts.uuid)/count(activecampaign.email_name)*100 as cr_rate
from il.mktg_activecampaign_email_opens activecampaign
full outer join bl.leads leads
on leads.uuid = activecampaign.uuid
full outer join bl.contracts contracts
on leads.uuid = contracts.uuid
and contracts.conversion_channel = 'crm'
group by activecampaign.campaign_step
The first three select parameters are working just fine but the fourth one is not displaying anything I would expect. Here's a screenshot of the table it's producing:
My expectation here for the second row would be to see 3.86 but nothing of the sort is showing unfortunately.
Would anyone be able to point me in the right direction to solve this :) ?
Thank you very much for your time!
SQL learner here, trying to make a join, but it seems to not work.
I have the following 2 tables:
#device_combined_players
#final_results2
The goal is to have a new table replacing the player_store_id from #final_results with the pseudo_name from #device_combined_players.
I have tried with:
SELECT #final_results2.player_store_id,
#device_combined_players.pseudo_name, #final_results2.genre FROM #device_combined_players INNER JOIN #final_results2 ON #final_results2.player_store_id = #device_combined_players.store_id
but I can't make it work, my output is simply an empty table.
Could you guys, please, give me some light? Thank you!
My expected result would be: as #final_results2 (image 2), but replacing player_store_id column by pseudo_name from #device_combined_players table.
EDIT: a screenshot with more details:
https://i.stack.imgur.com/lSyLb.png
And, I am answering myself, since I had 2 different issues here. Both are rookie mistakes, but I will leave them here so it helps somebody else in the future:
Take a look at the data type of your columns. They can cause conflicts if they are not the same as the columns you are referencing in a JOIN.
Check if your data doesn't have spaces. You can use TRIM and LEN to help you out answering this.
I sorted my problem like that.
I am very new to SQL and I am still trying to understand it. I was trying to find the average of a set of numbers but I don't know which function to use. In the SELECT statement , I wrote SELECT AVG as was written in the example I was working on and it returned error message 'Table Not Found'.
From the error message you gave, I think you have misunderstood how the avg keyword works.
Select avg(<the value you want to check the average of>)
FROM <table name here>;
Example
SELECT AVG(Price)
FROM Products;
Please note
As the comments on your threat states, please provide us with what SQL database you are using. Are you using PostgresSQL, mysql etc. Different SQL databases have different features and I can be helpful for us to know what you are using 😊
Also, if you can provide us with the information on the table (which fields the table contains) we can provide you with a more specific SQL query 😊
Here is a great tutorial that might help you further!
https://www.w3schools.com/sql/sql_count_avg_sum.asp
Hope this helps 😊
I' not getting an error message but i seem to be only getting 5 results no matter what i choose, so this leaves me to beleive that there is something wrong with my SQL statement. I'm usint node.js tedious to connect to sql 2008 r2 database. Previous statements worked, but that was a simple select statement with the posting date where clause. I know there are spaces in my column names which is not good practice, but there is nothing i can do about that this because thedatabase is utilized by Navision. Normally there are no line breaks, i just did that to make it appear more orderly to you guys.
SELECT
TA.[Amount],
TA.[Posting Date],
TA.[Entry No_],
TA.[Document No_],
TB.[Salesperson Code]
FROM [ShowTex Belgie NV$G_L Entry] as TA
LEFT OUTER JOIN [ShowTex Belgie NV$Sales Invoice Header] as TB
ON TA.[Document No_]=TB.[No_]
WHERE TA.[Posting Date]>'05/01/2015'
AND TA.[Document Type]='2'
AND TA.[Gen_ Posting Type]='2'
Strangely Enough the SQL turns out not to be the issu. It is the conversion from JSON.stringify to JSON.parse. I was certain i had tested this successfully before. But perhaps i was negligent. Anyways My code looks like this. when i Console.log(retVal) the data still looks correct about 100 reccords as expected.
retVal = JSON.stringify({result:dataSet});
fn(retVal);
function fn(retVal){
var obj = JSON.parse(retVal);
for(var i = 0; i<Object.keys(obj.result[0]).length;i++){
console.log(obj.result[i]);
}
}
If i console.log(retVal) inside the fn function i still get my wall of text as expected. but within the FOR statement i only get the first 5 records. Hmm I bet I'm headbutting a rookie mistake at the moment. :/
Totally depends on what you want but here is a cheat sheet with venn diagrams. http://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_orig.jpg so that it might be more logically to see what you are doing.
Wow, i found my problem. It's really embarrassing, the SQL was correct, i was counting the number of columns in my json file, this returned 5 each time. Sorry for Wasting people's time. Thank you so much for your feedback. It was helpfull in a sense that i was fixated on getting my sql statement wrong because I'm not good at those so your feedback was helpfull. It never occurred to me that I could still be running into rookie mistakes likes this.
i<Object.keys(obj.result[0]).length
needs to be
i<Object.keys(obj.result).length
this topic is rather cryptic for me cause I am no SAP/ABAP developer (SAP tables are for me just a datasource)
I have 2 tables COVP and GLPCA. I try to join them but I do not know on which key I can do that.
Any idea ? Thanks
COVP is a View (Two already 'joined' tables, being COEP and COBK).
To join them my guess without having any data to look at is join using the following rules;
GLPCA-RCLNT = COVP-MANDT
GLPCA-DOCNR = COVP-BELNR
GLPCA-REFDOCLN = COVP-BUZEI
GLPCA-KOKRS = COVP-KOKRS
EDIT: Looking in our system we don't actually use GLPCA. Exactly what data is it you are wanting to display against each other? I will edit my answer accordingly as I do not understand your requirements at the moment reading your comments above. Cheers