如何创建具有多个列名称的视图?

huangapple go评论62阅读模式
英文:

How can I create view with multiple name of columns?

问题

我在SQL问题上遇到了一些困难,我需要连接数据库中的所有表,但当我编写这个问题时,我只从“klienci”表中获取值,并按其余表的顺序排列。我还需要使用别名,因为接下来我需要用这个问题创建视图:

SELECT idk, klienci.nazwa AS nazwa_klienta, miasto, adres, telefon
FROM klienci
  LEFT JOIN zamow ON idk=k_id
  LEFT JOIN detal_zamow ON idz=z_id
  LEFT JOIN produkty ON idp=p_id;
英文:

I have problem with question in SQL, I need to join all tables from base but when I write this question I get only values from table "klienci" in order of rest tables. I need to use alias also, because next I need to create view with this question:

SELECT idk, klienci.nazwa AS nazwa_klienta, miasto, adres, telefon
FROM klienci
  LEFT JOIN zamow ON idk=k_id
  LEFT JOIN detal_zamow ON idz=z_id
  LEFT JOIN produkty ON idp=p_id;

答案1

得分: 1

SELECT k.idk, k.nazwa AS nazwa_klienta, k.miasto, k.adres, k.telefon,
z.,det_zam.,prod.*
FROM klienci AS k
LEFT JOIN zamow AS z ON k.idk=z.k_id
LEFT JOIN detal_zamow AS det_zam ON k.idz=det_zam.z_id --????
LEFT JOIN produkty AS prod ON k.idp=prod.p_id; --???

英文:
SELECT k.idk, k.nazwa AS nazwa_klienta, k.miasto, k.adres, k.telefon,
z.*,det_zam.*,prod.*
FROM klienci as k
LEFT JOIN zamow as z ON k.idk=z.k_id
LEFT JOIN detal_zamow as det_zam ON k.idz=det_zam.z_id  --????
LEFT JOIN produkty as prod ON k.idp=prod.p_id; --???

Not sure, but may be something like this. Without tables structure not sure about the two last JOINs

huangapple
  • 本文由 发表于 2023年3月31日 22:01:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定