-1

Let there be a table Person with attributes (columns) Name and Age.

Given the following expression in Domain Calculus:
{[name] | ∃ age (Person(name,age) ∧ age≥18)}

I want to create the corresponding SQL query.

Is it possible (not asking if it is good practice) to create such an SQL query (not only in this specific case) WITHOUT knowing the database schema? So I do not need to know that the table Person has the columns named Name and Age.

I have thought about accessing the table through column indices, but I am confused.

philipxy
  • 14,867
  • 6
  • 39
  • 83
CodingTil
  • 447
  • 2
  • 16
  • Define "convert" & "corresponding". (Same function of inputs? Certain parallel structure?) What SQL are you able to write? How can you relate it to answering this question? How is this even a practical programming problem if you're not stopped from writing SQL? [How do I ask and answer homework questions?](https://meta.stackoverflow.com/q/334822/3404097) [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) [ask] [help/on-topic] [Help] PS Yes-or-no questions including "is it possible" are poor Q&A, what do you really want to know? – philipxy May 01 '22 at 10:44
  • When defining aliases in FROM a new column name list can be given. – philipxy May 01 '22 at 10:52
  • Which SQL/DBMS? – philipxy May 01 '22 at 11:10
  • Does this answer your question? [Can I rename a MySQL Column without knowing the existing column name?](https://stackoverflow.com/questions/45175249/can-i-rename-a-mysql-column-without-knowing-the-existing-column-name) – philipxy May 01 '22 at 12:06
  • „Convert“ & „corresponding“ as defined by the english language. I have a expression set in domain calculus, I want a SQL query that returns the same result. – CodingTil May 01 '22 at 16:01
  • We use PostgreSQL, as indicated by the title of the question – CodingTil May 01 '22 at 16:01
  • No, I don’t think aliases will help, since I do not know the existing column names – CodingTil May 01 '22 at 16:03
  • @philipxy That might actually help. I‘ll look into it. But I cannot write two separate SQL Queries unfortunately – CodingTil May 01 '22 at 16:05
  • Please tag appropriately & don't put something only in the title. Please clarify via edits, not comments. The everyday words you used mean nothing in detail. I already gave 2 different things it could be referring to before you wrote your comment in reply. Use enough words to say what you mean, not just a vague word that can reasonably said to apply. Please do not say no when you haven't researched a suggestion. The standard SQL syntax when giving a table alias is ` ( )`. I don't know what you mean by "two queries". – philipxy May 02 '22 at 04:03
  • [Is there a generic workaround to express a derived column list in Oracle (and MySQL)?](https://stackoverflow.com/q/14127707/3404097) – philipxy May 02 '22 at 04:58

1 Answers1

0

Thanks to @philipxy I have stumbled upon this answer:

WITH p(name,age) AS (SELECT * FROM PERSON)
SELECT name FROM p WHERE age>=18
CodingTil
  • 447
  • 2
  • 16