I am new to SAP-MDG and I have added few customers using the standard SAP screens, I am interested in knowing if we can directly connect to MDG tables using Hana Studio.
Tables like MARA or KNA1, can I directly fire select queries on these tables?
select * from KNA1 fetch first 3 rows only;
something like this?
Thank you,
Divyesh Kalbhor
You can do this to store any three records from KNA1 into an internal table:
DATA: lt_KNA1 LIKE TABLE OF KNA1.
select * from KNA1 INTO lt_KNA1 up to 3 rows.
Related
Hello Stackoverflow i am facing problem in join records from master and detail table
using Sql Query
Master Table is Represented By Following Data
I Have Data in Detail Table
What I need in output is
What i tried is
I need sql select query to get the result shown above
SELECT distinct(master.voucherkey), detail.Amount FROM master ,detail
where master.voucherkey = detail.voucherkey
i.e. repeated voucherkey once and unique record many time thanks
You need to join the tables together rather than trying to select from both:
SELECT master.voucherkey, detail.Amount
FROM master
LEFT JOIN detail
ON master.voucherkey = detail.voucherkey
SQL cannot return merged rows like the picture.
I have an object in the database which has millions of accounts. Say there is another object which has the accounts that i need for building my report. I want to write a query that selects all from first object but only for the accounts that are in the second object.
If i write
select * from first f inner join second s on f.ID=s.ID
I'm getting the columns in second object which i don't want because there are similarly named fields in both and Tableau throws an error when i connect to it. Can someone help me with this?
Thakns
I want to write a query that selects all from first object but only for the accounts that are in the second object.
You've got these...
-- Object with mIlLiOns of accounts
millions
-- Object with accounts for your report
accounts_for_report
I'd start with something like...
SELECT mil.*
FROM millions mil INNER JOIN accounts_for_report afr
ON mil.ID = afr.ID;
If you wanted to accomplish this without a join (as the subject alludes), you can do this...
SELECT *
FROM millions mil
WHERE EXISTS (
SELECT * accounts_for_report WHERE ID = mil.ID
);
I'm quite a novice on this and I don't know if I will explain myself well. I am trying to do an exercise in SQL in which asks me to update the data in an "X" table from other data in a "Y" table. The problem is that it is not about updating table X exactly like the data in table Y. I put the statement and my tables:
Update the "numJocs" field (number of games) for all platforms, depending on the number of games each of the platforms in the GAMES table has.
PLATFORM table:
where: "nom" is name.
GAMES table:
where: "nom" is name, "preu" is price, "idPlataforma" is idPlatform and "codiTenda" is storeCode, but only idPlataforma interested for this exercise.
If I do:
SELECT COUNT(games.idPlataforma)
FROM games
GROUP BY (games.idPlataforma)
I can see how many games there are for each platform. The result would be:
count(games.idPlataforma)
__________________________
2
1
2
2
I would like to be able to put this result in the PLATFORM table, column "numJocs". But I don't know how to do it ... I also don't want to put it manually, that is, a "2" in a row "1", etc ... but I would like to be able to make a query and add that query in the column that I have to fill in. He tried to do a thousand things, but nothing ... Any help?
Thanks!!
for one time update you can use below query
update Product P
INNER JOIN (
SELECT games.idPlataforma, COUNT(games.idPlataforma) as cnt
FROM games
GROUP BY games.idPlataforma
) x ON P.id= x.idPlataforma
SET P.numJocs= x.cnt
For the next time on every entry of new game you have a update numJocs
Suppose you have 2 tables, table 1 and table 2:
Table 1:
Table 2:
You could insert new values into table 1, based on table 2 by doing the following:
insert into Table1(number,CFG) select ITEM,results from Table2
Which has the following result in table 1:
Any database should support the syntax using a correlated subquery:
update platforms
set numjocs = (select count(*)
from games g
where g.idPlatforms = platforms.id
);
I would caution you though about storing this value in the table. It will be immediately out of data if the platforms table changes. If you want to keep it in synch, then you need to create triggers -- and this is all rather complicated.
Rather, calculate the data on the fly:
select p.*,
(select count(*)
from games g
where g.idPlatforms = platforms.id
) as numjocs
from platforms p ;
You can put this in a view if you like. Many databases support materialized views where the results of the view are stored in a "table" and the table is kept up-to-date with the underlying data.
I am trying to run a query to get all the customers from my database. These are my tables in a diagram :
when running the query by joining the table Companies_Customers and the Customers table based on the customerId in both tables(doesn't show in the join table in the pic), I get duplicate rows, which is not the desired outcome.
This is normal from a database standpoint since a Customer can be related to different companies (Companies can share single customer).
My question is how do I get rid of the duplication via SQL.
There can be 2 approaches to your problem.
Either only select data from Customers table:
SELECT * FROM Customers
Or select from both tables joined together, but without CompanyName and with GROUP BY CompanyCustomerId - although I highly suggest the first approach.
I have a database with two tables, table 'product' and table 'factory'.
The table product has a column called factory_id and the table factory has both factory_id and 'factory_name'.
I have a bootstrap table which outputs all the fields the product table has, but how do I get the factory_name in there? I know I have to join tables but I don't really know how.
SELECT product.*, factory.factory_name
FROM product
LEFT JOIN factory ON product.factory_id = factory.factory_id;
This should work, but next time try including some code you tried yourself when you ask a question.