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;
}