sql鏈表
① sql 里 as 里的意思
as 就是給列 表 結果集 起別名
起的別名有很多用處 在鏈表查詢時不起別名最煩
涉及聯表查詢的時候你要指定某表的某列一般情況下是: 表.列 表名有時候又一大堆
起了別名後 就可以寫成 別名.列 因為有的表名字很長 你可以以這種方法給他縮減一些
就不需要再寫那麼一大堆沒用 又佔地形的東西了
在子查詢時 你要在一個查詢結果上再查東西 此時就必須娶個別名
如:
select * from (select * from ysyobjects )as Newtable
另 :
給列起別名可以達到顯示時以別名取代列名的效果
此外還有很多其他作用
如:創建觸發器、過程、函數 都可以用到
在創建存儲過程、視圖時 as的作用是指明存儲過程或者視圖的語句
② SQL怎麼把一個單鏈表分解成兩個單鏈表
程序如下:
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
char data;
struct node *nextPtr;
}*LinkList, Lnode;
static void CreateList(LinkList *headPtr, LinkList *tailPtr, char ch);
static void Decompose(LinkList *headPtrA, LinkList *headPtrB, LinkList *tailPtrB);
static void VisitList(LinkList headPtr);
static void DestroyList(LinkList *headPtr, LinkList *tailPtr);
int main(void)
{
LinkList headPtrA = NULL, tailPtrA = NULL, headPtrB = NULL, tailPtrB = NULL;
char ch;
while (1)
{
printf("Enter ch('@'-quit): ");
scanf(" %c", &ch);
if (ch == '@')
{
break;
}
else
{
CreateList(&headPtrA, &tailPtrA, ch);
}
}
VisitList(headPtrA); /* 列印絕薯分解前的鏈表 */
if (headPtrA != NULL) /* 鏈表不空的情並稿者況對其進行分解 */
{
Decompose(&headPtrA, &headPtrB, &敬悄tailPtrB); /* 對鏈表進行分解*/
}
else
{
printf("headPtrA is empty. ");
}
VisitList(headPtrA); /* 列印分解後的鏈表 */
VisitList(headPtrB);
DestroyList(&headPtrA, &tailPtrA); /* 銷毀鏈表 */
DestroyList(&headPtrB, &tailPtrB);
return 0;
}
static void CreateList(LinkList *headPtr, LinkList *tailPtr, char ch)
{
LinkList newPtr;
if ((newPtr = (LinkList)malloc(sizeof(Lnode))) == NULL)
{
exit(1);
}
newPtr -> data = ch;
newPtr -> nextPtr = NULL;
if (*headPtr == NULL)
{
newPtr -> nextPtr = *headPtr;
*headPtr = newPtr;
}
else
{
(*tailPtr) -> nextPtr = newPtr;
}
*tailPtr = newPtr;
}
static void Decompose(LinkList *headPtrA, LinkList *headPtrB, LinkList *tailPtrB)
{
int count = 0;
LinkList cA, pA;
char ch;
cA = NULL;
for (pA = *headPtrA; pA != NULL; cA = pA,pA = pA -> nextPtr)
{
ch = pA -> data;
count++;
if (count % 2 == 0)
{
CreateList(headPtrB, tailPtrB, ch);
cA -> nextPtr = pA -> nextPtr;
}
}
}
static void VisitList(LinkList headPtr)
{
while (headPtr != NULL)
{
printf("%c -> ", headPtr -> data);
headPtr = headPtr -> nextPtr;
}
printf("NULL ");
}
static void DestroyList(LinkList *headPtr, LinkList *tailPtr)
{
LinkList tempPtr;
while (*headPtr != NULL)
{
tempPtr = *headPtr;
*headPtr = (*headPtr) -> nextPtr;
free(tempPtr);
}
*headPtr = NULL;
*tailPtr = NULL;
}