Skip to main content
Examples of SQL Queries
Once data has been uploaded onto a SQL database it can be queried in a number of different ways. Here are some example queries. Note that some queries may not run on a particular relational database engine.

Find identifiers of a given type (typedefs, in this case):
select name from
ids left join tokens on ids.eid = tokens.eid
where ids.typedef = true

Number of different files that use a given identifier:
select name, count(*) as cf from (
select fid, tokens.eid, count(*) as c from
tokens
group by
eid, fid) as cl inner join ids on
cl.eid = ids.eid
group by ids.eid, ids.name
order by cf desc;

Number of times an identifier occurs in a single file:
SELECT IDS.NAME AS INAME, FILES.NAME AS FNAME, COUNT(*) AS C FROM TOKENS
INNER JOIN IDS ON
IDS.EID = TOKENS.EID
INNER JOIN FILES ON
TOKENS.FID = FILES.FID
GROUP BY IDS.EID, TOKENS.FID
ORDER BY C DESC;

Number of times an identifier occurs in the workspace:
select name, count(*) as c from tokens
inner join ids on
ids.eid = tokens.eid
group by eid
order by c desc

Reconstitute the file with fid = 4:
select s from
(select name as s, foffset from ids inner join tokens on
ids.eid = tokens.eid where fid = 4
union select code as s, foffset from rest where fid = 4
union select comment as s, foffset from comments where fid = 4
union select string as s, foffset from strings where fid = 4
)
order by foffset
The result will have newlines in the wrong places. Piping the output through a shell script like the following can fix this problem.
sed -e '/^[0-9][0-9]* rows/d' |
tr -d '\n' |
sed 's/\\u0000d/\
/g'
The above script will massage the HSQLDB output removing the trailing N rows line and all existing newlines, and changing the embedded \u0000d sequences into newlines. For the Windows line-end conventions the same script would be:
sed -e '/^[0-9][0-9]* rows/d' |
tr -d '\n\r' |
sed 's/\\u0000d\\u0000a/\
/g'

Show the projects each identifier belongs to:
select IDS.NAME, PROJECTS.NAME from IDS
INNER JOIN IDPROJ ON IDS.EID = IDPROJ.EID
INNER JOIN PROJECTS ON IDPROJ.PID = PROJECTS.PID
ORDER BY IDS.NAME;

Show the included files required by other files for each compilation unit and project.
select
projects.name as projname,
cufiles.name as cuname,
basefiles.name as basename,
definefiles.name as defname
from
definers inner join projects on definers.pid = projects.pid
inner join files as cufiles on definers.cuid=cufiles.fid
inner join files as basefiles on definers.basefileid=basefiles.fid
inner join files as definefiles on definers.definerid = definefiles.fid;

Speed-up processing:
create index teid on tokens(eid)
create index tfid on tokens(fid)

Obtain identifiers common between files participating in a define/use relationship:
SELECT
tokensa.eid,
min(ids.name) as identifier,
min(filesb.name) as defined,
min(filesa.name) as used
FROM definers
INNER JOIN tokens AS tokensa ON definers.basefileid = tokensa.fid
INNER JOIN tokens AS tokensb ON definers.definerid = tokensb.fid
INNER JOIN ids ON ids.eid = tokensa.eid
INNER JOIN files as filesa ON tokensa.fid = filesa.fid
INNER JOIN files as filesb ON tokensb.fid = filesb.fid
WHERE tokensa.eid = tokensb.eid
GROUP BY tokensa.eid, definerid, basefileid
ORDER BY defined, identifier

Create a function and macro call graph:
SELECT source.name AS CallingFunction, dest.name AS CalledFunction
FROM fcalls
INNER JOIN functions AS source ON fcalls.sourceid = source.id
INNER JOIN functions AS dest ON fcalls.destid = dest.id

Contents « Previous Next (Details of the Collected Metrics) »



Last change: Thursday, June 15, 2006 4:55 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.

Comments

Popular posts from this blog

MCA212 – ADVANCED DATA STRUCTURE BK ID B1476

ASSIGNMENT   DRIVE SPRING- 2018 PROGRAM MASTER OF COMPUTER APPLICATION SEMESTER II SUBJECT CODE & NAME MCA212 – ADVANCED DATA STRUCTURE BK ID B1476 NUMBER OF ASSIGNMNETS, CREDITS & MARKS 2, 4 Credits, and 30 marks each    ASSIGNMENT SET -1 Q.1. List and explain any Five types of graph.                                      10 Answer: - There are various types of graphs depending upon the number of vertices, number of edges, interconnectivity, and their overall structure. We will discuss only a certain few important types of graphs in this chapter. Null Graph A graph having no edges is called a Null Graph. Example (9899682018 What’s App and call) YOU CAN CONTACT US 10 A.M TO 8 P.M CHARGES – ASSIGNMENTS PER SEM 600, PER PAPER 150
should be approximately of 400 words. Each question is followed by evaluation scheme. Q.No Assignment Set -1 Questions Marks Total Marks 1 List and explain any Five types of graph. [5*2] 10 2 Explain 1. Fixed block storage allocation. 2. Variable block storage allocation [5+5] 10 3 What is the use of external Storage Devices? Explain any two external storage devices [4+3+3] 10 Q.No Assignment Set -2 Questions Marks Total Marks 1 Define algorithm and write a note on Complexity and Time- Space Tradeoff with example [2+4+4] 10 2 Define Queue and explain a. Array implementation of queue b. Linked list implementation of queue [2+4+4] 10 3 List the Advantages and Disadvantages of Linear and linked representation of tree. [5+5] 10

Business_Communication_and_Etiquette_-_Assignment_December_2018

Business_Communication_and_Etiquette_-_Assignment_December_2018                                                             NMIMS Global Access School for Continuing Education (NGA-SCE) Course: Business Communication and Etiquette Internal Assignment Applicable for December 2018 Examination 1. Large organizations where there are many people working closely, create unofficial and informal channels of communication. What is this kind of communication known as and what purpose does it serve in large organizations? List different types of this communication along with drawbacks if any. (10 Marks) 2. Explain the various forms that non-verbal communication takes which impacts cultural aspect of communication. How does verbal and non-verbal communication relate to each other? (10 Marks) 3. Zenstar Technologies has the task of collati...