从具有多个条件的单列获取多个行值

时间:2018-10-01 16:33:00

标签: mysql sql laravel

id   unique_id    name     franchise_id
1    MR1000       aaa      0
2    FR1001       bbb      0
3    GE1003       ccc      0
4    GE1004       ddd      0
5    CL1005       eee      2

这是我要从该表中获取记录的表

从找到带有ID的franchise_id 2搜索中获得第5条记录,并且也获得唯一的ID值

我需要这样的结果:

franchise_id     uniqueid     name
FR1001           CL1005       eee

2 个答案:

答案 0 :(得分:1)

您可以使用自连接和别名来做到这一点,从而覆盖真实列的名称。

as franchise_id

left join test as b on b.franchise_id = a.id将覆盖真实的列名,并将其作为新的列名返回。

franchise_id将表连接到自身,其中idb相匹配。

http://sqlfiddle.com/#!9/fb576f/11

如果a列没有引用,则所有join值都将为NULL。如果您需要匹配,可以将left类型从inner join连接更改为Sub InsertSectionBreak() ' Go to start of document Selection.HomeKey Unit:=wdStory ' Find next section based on header formatting, insert continuous section break just before ' Selection.Find.ClearFormatting Selection.Find.Style = ActiveDocument.Styles("Heading 1") With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Do While Selection.Find.Execute = True Selection.Find.Execute Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.InsertBreak Type:=wdSectionBreakContinuous Loop End Sub

http://sqlfiddle.com/#!9/1e9dad/2

答案 1 :(得分:0)

我会简单地做:

def Draw_Card():
    Rank = random.randint(1, 13)
    Card = str(Rank)

    if Rank == 11:
        Card = "J"
    elif Rank == 12:
        Card = "Q"
    elif Rank == 13: 
        Card = "K"

    Suit = random.randint(1, 4)
    if Suit == 1:
        Card = Card + "D"
    elif Suit == 2:
        Card = Card + "C"
    elif Suit == 3:
        Card = Card + "H"
    elif Suit == 4:
        Card = Card + "S"

    return Card

print("And the game begins!")
Card = "Nothing"
Card = Draw_Card()
print(Card